-1
#include <iostream>
using namespace std;

int Main ()
{
    cout << "---------------------------------------------------------------------------------/n";
    cout << "NAME: Justin Chiang/n";
    cout << "COMPUTER LANGUAGES: Python, Lua, C++/n";
    cout << "FAVORITE VIDEO GAME: Starcraft, Diablo/n";
    cout << "I'm taking this class for math undergrad requirement and because it is very useful." << endl;
    system("PAUSE");
    return 0;
}

输出:

1>------ Build started: Project: HW1, Configuration: Debug Win32 ------
1>  HW1.cpp
1>c:\users\asus\desktop\hw1\hw1\hw1.cpp(5): warning C4627: '#include <iostream>': 
            skipped when looking for precompiled header use
1>          Add directive to 'StdAfx.h' or rebuild precompiled header
1>c:\users\asus\desktop\hw1\hw1\hw1.cpp(25): fatal error C1010: unexpected end of file 
            while looking for precompiled header. Did you forget to add '#include  
            "StdAfx.h"' to your source?
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
4

3 回答 3

3

转到项目属性。单击 Configuration Properties/C/C++/Precompiled Header 并选择“Not Using Precompiled Headers”选项。确切的说明可能会根据您使用的 Visual Studio 版本而有所不同,但基本上您希望关闭预编译头文件。

于 2012-09-10T05:45:22.537 回答
2

你不见了#include "stdafx.h"

此外,int Main()不是标准 C++,你应该用int main()or替换你的 main 函数int main(int argc, char** argv)

既然我不得不说为什么你必须使用预编译的头文件,它可以使 MSVC 的编译时间更快,但它阻碍了可移植性,并且如果使用它会拖拽很多不符合标准的代码。它可能会破坏您的可移植性,但如果您正在使用另一个 IDE,您可以轻松地删除头文件。

于 2012-09-10T05:44:12.660 回答
0

int Main ()应该是小写。将其更改为int main ().

更改cout << "... /n";cout << "... \n";

#include <iostream>
using namespace std;

int main ()
{
    cout << "---------------------------------------------------------------------------------\n";
    cout << "NAME: Justin Chiang\n";
    cout << "COMPUTER LANGUAGES: Python, Lua, C++\n";
    cout << "FAVORITE VIDEO GAME: Starcraft, Diablo\n";
    cout << "I'm taking this class for math undergrad requirement and because it is very useful." << endl;
    system("PAUSE");
    return 0;
}
于 2012-09-10T07:21:16.280 回答