【发布时间】:2011-01-19 06:37:41
【问题描述】:
我正在尝试学习 c++,但我阅读或查找的大多数教程和书籍都会教你这个......
(我假设像大多数教程一样,他们一开始就在 win32 控制台或 CLR 控制台中教授代码。在任何一种情况下,以下方法都不起作用。)
#include <iostream>
int main( )
{
std::cout << "Hello World\n";
return (0);
}
我的 IDE 是 Visual C++ 2008 Express 版本,他们接受这样的代码
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
或者像这样
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
Console::WriteLine(L"Hello World");
return 0;
}
老实说,我在这些方面都没有区别,我不确定我是否应该下载一个较旧的编译器以便它工作。如果有人能告诉我这些有什么区别以及从那里去哪里。这将有很大帮助。谢谢 [已编辑]
我正在尝试做一个简单的hello world。但我收到错误“系统找不到指定的路径”。我有屏幕截图显示错误的样子。当我在构建文件之前清楚地保存文件时,这也意味着我的项目已经过时了。显然它找不到可执行文件。我去了调试文件夹,没有看到任何 .exe 文件。
[已编辑]
好的,现在当我尝试构建项目时,出现以下错误
1>------ Rebuild All started: Project: test, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'test', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>test.cpp
1>c:\users\numerical25\desktop\test\test\test.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
1> Add directive to 'stdafx.h' or rebuild precompiled header
1>c:\users\numerical25\desktop\test\test\test.cpp(6) : error C2653: 'std' : is not a class or namespace name
1>c:\users\numerical25\desktop\test\test\test.cpp(6) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Users\numerical25\Desktop\test\test\Debug\BuildLog.htm"
1>test - 2 error(s), 1 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
这是我使用的代码
#include <iostream>
#include "stdafx.h"
int main( )
{
std::cout << "Hello World\n";
return (0);
}
注意:我尝试在有和没有#include "stdafx.h" 的情况下使用它当我在没有#include "stdafx.h" 的情况下尝试它时,它说我可能会错过它。
【问题讨论】:
-
不禁想起呆伯特:“这里是个傻孩子……”:tomayko.com/writings/that-dilbert-cartoon。不完全公平,但太有趣了,不容错过。不了解windows,所以我不能提供任何严肃的建议。
-
stdafx.h 必须是 cpp 中的第一个标头。
-
我将答案更新为灵丹妙药。随意更改您的接受的答案。 :)
-
大声笑,你得了 18 分!我得把它给保罗。他第一个得到它
标签: c++ visual-c++