更新时间2018-08-07 16:34:44
C:UsersDell>gcc 5-1.cpp -o 5-1C:UsersDellAppDataLocalTempccLyfQvy.o:5-1.cpp:(.text+0x20): undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()'
C:UsersDellAppDataLocalTempccLyfQvy.o:5-1.cpp:(.text+0x2e): undefined reference to `std::cin'
上面是编译后一长串中的前两行,用gcc编译c程序时还没有出现过问题,下面是编译的c++程序
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
string line;
while(getline(cin, line))
{ int x, sum = 0;
stringstream ss(line);
while(ss >> x) sum += x;
cout << sum << " "; }
return 0;
}
你用gcc编译C++的程序,命令行不能用gcc
要用g++的,以下是完整命令
g++ 5-1.cpp -o 5-1