【发布时间】:2010-10-04 16:54:11
【问题描述】:
将字符串或 char* 指针放入 istream 的最佳方式是什么。
我想做以下事情
std::string a = "abc..";
//I know this can be done, not sure if this is most efficient
// and not sure about char* pointers
std::istringstream istr (a);
...
foo (istr);
void foo(std::istream& is) {
}
【问题讨论】:
-
对不起;你在这里问什么并不完全清楚。您希望能够像访问流一样访问字符串吗?你想完成什么?
-
现在编辑了问题。
-
我应该注意到您的代码无效。您不能从 istringstream 构造 istream。你认为它应该做什么(注意,流不能被复制)。
-
编辑了我的用例,如果我想使用 istringstream 到 istream,我想我可以使用 up_cast