无法在c ++中打开包含文件sstream.h

时间:2012-06-18 12:33:43

标签: c++ header

我正在尝试使用标头文件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

有没有人知道我做错了什么?

1 个答案:

答案 0 :(得分:3)

有很多问题,请尝试以下方法:

#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
  • {li> <cstdio> getchar
  • 使用string
  • 限定stringstreamstd::
  • sstream,而不是sstream.h