2

我正在尝试使用头文件sstream.h下面是我的代码段

  #include <iostream>
 #include <string>
 #include <sstream>

 int main ()
{
string mystr;
float price=0;
int quantity=0;

cout << "Enter price: ";
getline (cin,mystr);
stringstream(mystr) >> price;
cout << "Enter quantity: ";
getline (cin,mystr);
stringstream(mystr) >> quantity;
cout << "Total price: " << price*quantity << endl;
return 0;
  } 

但我收到以下错误

unable to open include file sstream.h

有谁知道我做错了什么?

4

1 回答 1

4

有很多问题,试试下面的:

#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>

int main()
{
 std::string st = "23 53";
 int result;
 std::stringstream(st) >> result;
 getchar();
 return 0;
}

一些:

  • getchar代替getch
  • <cstdio>为了getchar
  • 有资格stringstringstreamstd::
  • sstream, 不是sstream.h
于 2012-06-18T12:39:19.627 回答