在类里面,我的任务是为一个已经定义的类编写一个方法,并且不能更改类定义、头文件或#include 语句。
我需要使用这段代码将一个字符串拆分成不同的变量,
istringstream ss(line)
ss >> plu >> descp >> one >> price >> weight
不能使用#include
我试过了,
istringstream::istringstream ss(line)
std::istringttream:istringstreeam ss(line)
std::istringstream ss(line)
而且这些都没有编译,我真的不知道在 C++ 中包含文件是如何工作的。
最佳答案
How can I use istringstream when I cannot use #include < sstream>? Is there a way in c++ to directly call that method instead of #including it in the definitions?
无需复制和粘贴 std::istringstream
的声明来自 <sstream>
的类(class)将头文件添加到您的文件中,编译器无法知道为 ss
分配多少大小.所以我会说:不,没有简单的解决方法。
关于c++ - 使用不带 #include <sstream> 的 istringstream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19148747/