为什么我的第一个使用 dev-c++ 的程序不工作?
Why is my first program using dev-c++ not working?
我已经安装了 devc++ 并编写了一个基本的 hello world 程序
#include<stdio.h>
int main
{
cout<<"hello";
return 0;
}
这是我的运行。但是,在 运行 编译代码
时出现以下错误
3 1 D:\cpp\helloworld.cpp [Warning] extended initializer lists only
available with -std=c++11 or -std=gnu++11
4 4 D:\cpp\helloworld.cpp [Error] 'cout' was not declared in this scope
5 4 D:\cpp\helloworld.cpp [Error] expected unqualified-id before
'return'
6 1 D:\cpp\helloworld.cpp [Error] expected declaration before '}' token
有人请帮忙!
试试这个:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
这样的东西应该很容易在 cplusplus.com 上找到
http://www.cplusplus.com/forum/general/49600/
在你的第一行代码中,你使用了 #include<stdio.h>
这是一个 c preprocessor 指令,但是在 main 函数中你使用了 cout<<"hello";
这是一个 C++ 代码。
对于 C 代码,你需要使用这样的东西:
#include <stdio.h>
int main(void)
{
printf("hello");
return 0;
}
而在 C++ 中(阅读 C++ Language),您需要使用如下内容:
#include <iostream>
int main()
{
std::cout << "hello";
return 0;
}
或
#include <iostream>
using namespace std;
int main()
{
cout << "hello";
return 0;
}
我已经安装了 devc++ 并编写了一个基本的 hello world 程序
#include<stdio.h>
int main
{
cout<<"hello";
return 0;
}
这是我的运行。但是,在 运行 编译代码
时出现以下错误3 1 D:\cpp\helloworld.cpp [Warning] extended initializer lists only
available with -std=c++11 or -std=gnu++11
4 4 D:\cpp\helloworld.cpp [Error] 'cout' was not declared in this scope
5 4 D:\cpp\helloworld.cpp [Error] expected unqualified-id before
'return'
6 1 D:\cpp\helloworld.cpp [Error] expected declaration before '}' token
有人请帮忙!
试试这个:
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
这样的东西应该很容易在 cplusplus.com 上找到 http://www.cplusplus.com/forum/general/49600/
在你的第一行代码中,你使用了 #include<stdio.h>
这是一个 c preprocessor 指令,但是在 main 函数中你使用了 cout<<"hello";
这是一个 C++ 代码。
对于 C 代码,你需要使用这样的东西:
#include <stdio.h>
int main(void)
{
printf("hello");
return 0;
}
而在 C++ 中(阅读 C++ Language),您需要使用如下内容:
#include <iostream>
int main()
{
std::cout << "hello";
return 0;
}
或
#include <iostream>
using namespace std;
int main()
{
cout << "hello";
return 0;
}