在g++ubuntu中编译简单的helloworldc++程序时出现多个错误
multiple errors while compiling simple hello world c++ program in g++ ubuntu
下面是我在nano编辑器中编写的helloworld程序。
#include<iostream>
using namespace std;
int main
{
cout<< "Hello world";
return 0;
}
当我编译它的时候,我得到了这么多错误。
ello.cpp:4:5: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
int main
^
hello.cpp:6:22: error: expected ‘}’ before ‘;’ token
cout<< "Hello world";
^
hello.cpp:6:6: error: invalid user-defined conversion from ‘std::basic_ostream<char>’ to ‘int’ [-fpermissive]
cout<< "Hello world";
^
In file included from /usr/include/c++/4.8/ios:44:0,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iostream:39,
from hello.cpp:1:
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note: candidate is: std::basic_ios<_CharT, _Traits>::operator void*() const [with _CharT = char; _Traits = std::char_traits<char>] <near match>
operator void*() const
^
/usr/include/c++/4.8/bits/basic_ios.h:115:7: note: no known conversion for implicit ‘this’ parameter from ‘void*’ to ‘int’
hello.cpp:7:2: error: expected unqualified-id before ‘return’
return 0;
^
hello.cpp:8:2: error: expected declaration before ‘}’ token
}
请帮帮我。
您错过了将main()
标记为函数的括号:
#include <iostream>
int main() {
std::cout << "!!!Hello World!!!" << std::endl;
return 0;
}
请注意,如果显式使用std::cout
和std::endl
而不是using
整个namespace std
(如果您不清楚发生了什么,这可能会让您感到困惑),则更容易理解名称空间。或者,至少要清楚你是什么using
:
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout << "!!!Hello World!!!" << endl;
return 0;
}
相关文章:
- 程序崩溃并显示"std::out_of_range"错误
- xmake总是报告:错误:无法获取cxx的程序,为什么
- VSCode-有一个红色下划线,但程序构建和运行正确,并且出现配音错误
- 分段错误当我试图运行程序时出错
- 显示错误输出的简单数组排序程序
- 示例外壳应用程序显示的 V8 "segmentation fault (core dumped)"错误
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- 为什么程序在 c++ 中迭代 emtpy 向量时会抛出运行时错误
- 在气泡排序程序中未声明错误功能
- 我在c ++矩阵计算器程序中找不到错误
- 叮当格式化程序多行格式配置错误
- 全局向量导致 C++ 程序结束时出现段错误
- 运行时间错误:程序跳过提示,以获取第二名和第三个名称
- Glibc 2.7 配置错误程序太旧
- 运行时错误:程序已停止响应
- OpenCV for Android:在 PATH 中找不到错误程序"sh"
- C++中的 scanf 错误 - 程序没有响应
- c++语法错误:程序以非零状态退出
- 运行时错误C++程序:检测到glibc,munmap_chunk(),指针无效
- libxml2错误程序c++