c++ - 使用不带 #include <sstream> 的 istringstream

标签 c++

在类里面,我的任务是为一个已经定义的类编写一个方法,并且不能更改类定义、头文件或#include 语句。

我需要使用这段代码将一个字符串拆分成不同的变量,

istringstream ss(line)
ss >> plu >> descp >> one >> price >> weight

不能使用#include 时如何使用istringstream?在 C++ 中有没有一种方法可以直接调用该方法而不是 #include it in the definitions?

我试过了,

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/

相关文章:

C++:创建迭代器嵌套类的实例

C++/OpenGL : VAOs work individually but not together

c++ - 为什么运算符 << 不明确?

c++ - 编译器如何在 C++ 中获取 const 的地址?

c++ - 如何模板化外部数组?

c++ - glReadPixels 存储 x, y 值

c++ - 在不锁定文件的情况下同时更新文件

c++ - 在基类构造函数中使用 `this` 是否有效?

c++ - 如何在 Eclipse 中运行使用 MinGW 编译的 C++ 程序?如何 "link(?)"?

c++ - 查找 sizeof char 数组 C++