visual studio 2012 c++ hello world - iostream not working

前端 未结 6 933
轮回少年
轮回少年 2021-02-08 21:48

I have an issue with Visual Studio\'s 2012. I am also using \"Sams Teach Yourself C++ in One Hour a day, 7th edition\".

After using google to find the \"best\" compilers

相关标签:
6条回答
  • 2021-02-08 22:30

    The apostrophes you used are wrong:

    “Hello World!” 
    

    should be

    "Hello World!"
    

    Notice even how SO recognizes the difference. You should at least type the code you see in the book instead of copying and pasting it. ;-)

    0 讨论(0)
  • 2021-02-08 22:32

    The difference between

    “Hello World!” and 
    "Hello Nik" is the apostrophe. 
    

    Aslo is the error persists than just check visual c++ library linker.

    There is aslo definitely no need for conio.h

    If your going to copy from a book at least copy it correctly.

    Using namespace std; 
    would be pretty smart in this case. 
    
    0 讨论(0)
  • 2021-02-08 22:35

    The Win32 console application is actually quite different from the empty project. Win32 utilize a message (input) queue which you poll in a loop and your program respectively utilizes the Win32 API and performs certain operations.

    The empty project is a bit less dependent on Win32 or anything that Windows provides in terms of API unless you make it dependent on it. This would be the simples hello world app in you empty project:

    #include <iostream>
    
    using namespace std;
    
    int main() 
    {
        cout << "Hello World" << endl;
    
        return 0;
    }
    
    0 讨论(0)
  • 2021-02-08 22:39

    Just try this::

    "Hello World!" instead of “Hello World!”.

    0 讨论(0)
  • 2021-02-08 22:52

    In order to fix your error you have to delete std:: of std::cout and std::endl, and write using namespace std; underneath #include iostream and and change “ ” with " ".

    #include <iostream>
    using namespace std;
    int main() 
    {
       cout <<"Hello World" << endl;
       return 0;
    }
    

    In Visual studio 2012

     file>new projet>visual c++ (Project win32)>application settings(application console+Not Using Precompiled)>in right box in you Project (right click, add>new element>file c++).
    
    0 讨论(0)
  • Besides aphostrophes you may need to disable precompiler headers in project properties.

    They are turned on by default in VS2012. If you are not familiar with precompiled headers turn them off.

    1. Right click on project (not solution)
    2. Click properties.
    3. Expand "Configuration properties"
    4. Expand "C/C++"
    5. Choose "Precompiled headers"
    6. Set "Precompiled header" to "Not Using Precompiled Headers"

    More information about precompiled headers and stdafx.h file at Wikipedia

    0 讨论(0)
提交回复
热议问题