Thread: Having trouble getting started with Microsoft Visual C++

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    Having trouble getting started with Microsoft Visual C++

    sean_mackrory says:

    A database error occurred while this thread was being split. This post was not intended to be a part of this thread. Apologies to those whose posts in the initial thread were lost.

    Thank you.

  2. #2
    Registered User
    Join Date
    Sep 2005
    Posts
    2
    Hi All,

    Rather then post another "newb" thread, I thought I would just toss out a little problem I am having here instead.

    My basic problem to the entire C++ newbie experience, is using the compiler. All of these tutorials, tell you to do this fine little hello world simple program, but not one, tells you where to type it, or even how to open a compiler.

    I have MS Visual Studio via work (including Visual C++). If you select to open a new file, there are about 800 choices.

    I have been through numerous tutorials, on getting started, searched and searched, and short of my paying to go to MS training, I can not find anything to get me going.

    Does anyone have any suggestions on where to find some beginners guide to Visual C++ (for free), or can at least tell me where I input this syntax into Visual C++? From launch to the typing in of the text. (I have figured out the compile portion, but really do not know what project to pick to get going).

    Many thanks in advance.
    Last edited by Flak; 09-19-2005 at 02:51 PM.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What version of Visual Studio do you have. The instructions depend on the version.

    Basically, you want Win32 Console Application, and you want change the settings to be an empty project in the wizard.

    Once you have the project set up you need to create a C++ source file and ad it to the project. if your project requires multiple files create them and add them to the project. The IDE will compile all the source files when you build. As long as one of them has a main() function (and there are no errors), your program will build successully and can be run or executed.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Copying this out of my tutorial-in-progress. (Not available online yet.)

    Visual Studio
    Visual Studio offers quite a lot of project types. We don't need anything specialized, though.
    Choose File->New->New Project. The Project wizard is launched. For the project type, you choose Win32 Console Project from the C++ area.
    After entering a name (I use skunk) and a location for the project, you can click Next.
    You can now edit the project properties. Click the Properties link on the left side of the wizard. On the page that comes up, check the Empty Project checkbox. If you don't, you'll end up with a lot of autogenerated stuff that can be quite confusing.
    Click Finish. Visual Studio will create the project for you.
    Grab hello.cpp and put it into your project directory. In the project explorer, right-click the Source Files folder and choose Add->Add Existing. Select hello.cpp and click Add. The file is now part of your project.
    Choose Build->Compile or hit the appropriate hotkey. (That would be F7 for my configuration, but that's not the default.) This will start the build process. A small message window will appear at the bottom, showing you the progress. If nothing goes wrong, it will finish by reporting success.
    Choose->Build->Execute to launch the program. A console window will pop up, containing the words "Hello, world!" on the first line. You've done it!
    These instructions are for Visual Studio.Net 2003. Here are the contents of the mentioned file:
    Code:
    #include <iostream>
    
    int main()
    {
    	std::cout << "Hello, world!" << std::endl;
    }
    If you want to add a new file, right-click the folder in the project explorer and choose "Add New..." (or something like that). From the resulting wizard, you want a C++ source file (.cpp). You can actually choose anything, as long as you add the extension .cpp in the filename box.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    I actually use Visual Studio .NET 2003 Enterprise Architect. If you wish to do that in VS, you would have to put it in this format:

    Code:
    #include "iostream"
    using namespace std;
    
    void main(void)
    {
         cout << "Hello World!" << endl;
    }

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    CornedBee's code will work in VC++ 6.0 (I assume that's what you meant), it just has a warning. Your format is not necessary to get rid of the warning, and adds a couple unnecessary changes. On VC++ 6.0 try:
    Code:
    #include <iostream>
    
    int main()
    {
        std::cout << "Hello, world!" << std::endl;
        return 0;
    }

  7. #7
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    Ah, I should have realized that, my bad, oh well, my post might help people with 2003.

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    CornedBee's code works perfectly with .NET 2003.

  9. #9
    Registered User
    Join Date
    Sep 2005
    Posts
    6
    There are many different tutorials, such as the one posted before me, and ones like the one I have posted. Many people get confused. I most certainly did when I was first beginning. Maybe they both work perfect in .NET 2003. But maybe it was better that now 2 different ways have been posted. One thing people do need to learn when they are learning C++ is the different ways code can be written. Am I wrong? It will definitely help them when they read many different tutorials and such.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The thread got messed up... in case my post didn't get through:

    The problem is that your code has incorrect C++ (void main instead of int main). In addition, it has an unconventionable construct ("iostream" instead of <iostream>) and a debatable one (using directive instead of std:: ). Alternate versions are fine but incorrect alternate versions can be detrimental.

  11. #11
    Registered User
    Join Date
    Sep 2005
    Posts
    2
    Thanks for all the help.

    My apologies as well to the original post, I was trying to avoid clutter, and creating redundant threads, and it ended up causing a problem anyway...

    Corned, i will try to open VC++ per your instructions, and let you know what i find out.

    Yes its VS6.0

    THanks again all,

    Flak

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    CornedBee's instructions are for a later version Visual C++, so you might not be able to follow them exactly in version 6.0. They idea is still basically the same, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. clrscr() in microsoft visual c++
    By canliceset in forum C++ Programming
    Replies: 7
    Last Post: 11-18-2004, 02:40 AM
  5. Microsoft Visual Studio.net Professional
    By nbo10 in forum C++ Programming
    Replies: 5
    Last Post: 07-25-2003, 12:52 PM