gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:01:24 29 4
gpt4 key购买 nike

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

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

最佳答案

有很多问题,请尝试以下操作:

#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

关于c++ - 无法在 C++ 中打开包含文件 sstream.h,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11082991/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com