首页 > 电脑

用gcc编译c++程序时出现问题

更新时间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

上一篇:除了vbs,bat,txt,cmd,vbe还有什么和这些一样的

下一篇:想要进行无人机编队控制,有经验的来说说怎么实现?