Thread: Visual C++ 2010 problem.

  1. #1
    Registered User
    Join Date
    May 2010
    Posts
    62

    Visual C++ 2010 problem.

    I just downloaded Visual C++ and I am trying it out now but I got a problem. I can not seem to find how to create a new console application. I keep getting errors when I try to build an application. Next to that when I open a new file the example code that it displays for the "hello wolrd!" program looks nothing like C++ coding to me. I am trying to build the following program.
    Code:
    #include<iostream>
    #include<string>
    
    using std::cout;
    using std::cin;
    using std::endl;
    using std::string;
    
    int main()
    {
    	cout << "Please enter your name: ";
    	string name;
    	cin >> name;
    	cout << endl;
    	cout << "Your name is " << name;
    
    	return 0;
    }
    I know I did not code anything wrong because I can build it in CodeBlocks. Maybe someone could help me out here and explain to me step by step how I should build a console application coded in C++ in Visual C++ 2010 because I seem to be doing something wrong. And please explain why the example code looks nothing like C++ to me. It uses thefollowing statement for example instead of "std::cout" "console.writeline. And why it includes a file called "#include "stdafx.h"". I never seen that header file in my book and thought those statements where included in the header "iostream".

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    can you post the code of the program that "looks nothing like C++ coding"? visual studio sometimes tries to force you to do things its own way, with things like tmain and tchar, and stdafx.h, but none of this is really necessary. you can just write code the way your book or tutorial or whatever says. Also, when you get error messages, please post them exactly as they show on your screen, otherwise it's very difficult for us to help you.

  3. #3
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    When starting a new project, I always start with "Empty Project". This ensures that VS doesn't add anything "helpful".
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    As well as starting with an empty win32 console project, make sure

    Project->settings->compiler->pre-processor->use precompiled headers is OFF
    This gets rid of the need for stdafx.h magic.

    Project->settings->compiler->somewhere
    The UNICODE setting is OFF
    IIRC, the default in VC2010 is to compile UNICODE enabled programs.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Actually, it's just under the project properties (general). Character set should be set to multi-byte or not set to avoid unicode.
    stdafx.h is a precompiled header. Reduces compile-time. Google it if you want to know more.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    If you remove stdafx.h b/c you are not using pre-compiled headers you will want to take the includes from it and place them in another header and include that or your code will not compile.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The problem in this program is that Visual Studio's default project uses precompiled headers, and uses them in a very stupid way. Specifically, if you remove the stdafx.h include that's there by default, you will get errors.
    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

  8. #8
    Registered User
    Join Date
    May 2010
    Posts
    62
    Quote Originally Posted by Salem View Post
    As well as starting with an empty win32 console project, make sure

    Project->settings->compiler->pre-processor->use precompiled headers is OFF
    This gets rid of the need for stdafx.h magic.

    Project->settings->compiler->somewhere
    The UNICODE setting is OFF
    IIRC, the default in VC2010 is to compile UNICODE enabled programs.
    I do not want to skip any of your advise but if I would do as suggested in this post is there then still any need to include stdafx.h or can I just code along from my book and I will not encounter any problems later when I try to build the program?

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    AFAIK, you should be able to compile "out of the box" in regular standard C++.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    May 2010
    Posts
    62
    I managed to build the program using the following settings.

    New project -> Windows32 console application

    tab:
    Application type: Console application.
    Add common header files for: both options are greyed out.
    Additional options: Empty project.

    The program:
    Code:
    #include<iostream>
    #include<string>
    
    using std::cin;			using std::cout;
    using std::endl;		using std::string;
    
    int main()
    {
    	cout << "Please enter your name here; ";
    	string name;
    	cin >> name;
    	cout << endl;
    	cout << "Your name is" << name;
    
    	system("PAUSE");
    
    	return 0;
    }
    However in the output window I get the following:
    'sug.exe': Loaded 'C:\Documents and Settings\myname\My Documents\Visual Studio 2010\Projects\sug\Debug\sug.exe', Symbols loaded.
    'sug.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
    'sug.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
    'sug.exe': Loaded 'C:\WINDOWS\system32\msvcp100d.dll', Symbols loaded.
    'sug.exe': Loaded 'C:\WINDOWS\system32\msvcr100d.dll', Symbols loaded.
    'sug.exe': Loaded 'C:\WINDOWS\system32\apphelp.dll', Cannot find or open the PDB file
    'sug.exe': Loaded 'C:\WINDOWS\system32\version.dll', Cannot find or open the PDB file
    'sug.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Cannot find or open the PDB file
    'sug.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', Cannot find or open the PDB file
    'sug.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Cannot find or open the PDB file
    The program '[3344] sug.exe: Native' has exited with code 0 (0x0).
    Now the questions come.

    1. What does the output given in the output window means. Is it anything I am doing wrong or can prevent?
    2. Why is there the need to pause the system. I am happy I found how to do it but in CodeBlocks there was no need to do it. Can it be set so I do not need to include a system pause?
    3. How do I create an executable using Visual C++? After I build no executable seems to be created or is it stored in a different location?

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by Kitt3n View Post
    However in the output window I get the following:
    There's nothing wrong with this output. It's just telling you which DLLs it loads and if it can find debug information for them.

    2. Why is there the need to pause the system. I am happy I found how to do it but in CodeBlocks there was no need to do it. Can it be set so I do not need to include a system pause?
    Choose "Run without debugging" instead of "Run" to launch the program (Ctrl+F5 instead of just F5).

    3. How do I create an executable using Visual C++? After I build no executable seems to be created or is it stored in a different location?
    It is created, and its path is actually visible in the output window.
    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

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Alternatively, a breakpoint on the closing brace (F9 typically).
    And yes, you can safely ignore that output.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    May 2010
    Posts
    62
    Thanks. Stupid of me not to have seen the link to the .exe in the output window.

    However even if I can ignore it what does this exactly mean "Cannot find or open the PDB file", what is a PDB file?

    Next to that it seems that even if I do not use them it adds a lot of header files in the folder "external dependencies" why is this?

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    PDB is a file format that contains debug information. Basically it allows you to debug applications / libraries. But Microsoft does not ship debug information for system files such as ntdll.dll. That is why you see "could not load PDB". Your own application has a PDB file in your Debug directory.

    External dependencies is all the files your application relies on (or should be). If you include iostream, it includes a lot of other headers. They should be shown there.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Registered User
    Join Date
    May 2010
    Posts
    62
    Ok, thanks.

    It kind of confused me to see header files like math.h there knowing the only thing I was using was std::cin, std::endl, std::string and std::cout beside the system pause.

    So as long as I end with exit code 0 "true" the build was successful?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Visual Studio 2010 coming for Mac OS X
    By DavidP in forum General Discussions
    Replies: 5
    Last Post: 05-26-2011, 09:49 AM
  2. Visual Studio 2010 Express vs 2005 Standard
    By micahharwell in forum Windows Programming
    Replies: 6
    Last Post: 06-13-2010, 07:45 AM
  3. Visual studio.net C++ Problem
    By Dina in forum C Programming
    Replies: 5
    Last Post: 07-19-2008, 02:34 PM
  4. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 03:22 AM
  5. Visual Basic Adodc Problem
    By rahat in forum Windows Programming
    Replies: 1
    Last Post: 01-20-2002, 06:55 AM