Tag: stringstream

将stringstream内容写入到stream中

我目前使用std::ofstream如下: std::ofstream outFile; outFile.open(output_file); 然后,我尝试将std::stringstream对象传递给outFile ,如下所示: GetHolesResults(…, std::ofstream &outFile){ float x = 1234; std::stringstream ss; ss << x << std::endl; outFile << ss; } 现在我的outFile除了垃圾outFile什么也没有包含:“0012E708”全部重复。 在GetHolesResults我可以写 outFile << "Foo" << std:endl; 它会在outFile正确输出。 任何build议我做错了什么?

C#中的StringStream

我希望能够从我从Stream创build的类创build一个string。 具体来说,我想能够写这样的代码: void Print(Stream stream) { // Some code that operates on a Stream. } void Main() { StringStream stream = new StringStream(); Print(stream); string myString = stream.GetResult(); } 我可以创build一个名为StringStream的类吗? 还是已经有这样的课程了? 更新:在我的示例中, Print方法在第三方外部DLL中提供。 正如你所看到的, Print期望的是一个Stream 。 打印到Stream ,我希望能够以string的forms检索它的内容。

%02d等同于std :: stringstream?

我想输出一个整数到一个std::stringstream与printf的%02d的等效格式。 有一个更简单的方法来实现这个比: std::stringstream stream; stream.setfill('0'); stream.setw(2); stream << value; 是否有可能将某种格式的标志传输到stringstream ,如(伪代码): stream << flags("%02d") << value;

为什么不允许复制stringstream?

int main() { std::stringstream s1("This is my string."); std::stringstream s2 = s1; // error, copying not allowed } 我无法find为什么我不能复制stringstream的原因。 你能提供一些参考吗?

为什么stringstream >>更改目标失败的值?

从Stroustrup的TC ++ PL第3版第21.3.3节: 如果我们尝试读入variablesv并且操作失败,则v的值应该保持不变(如果v是istream或ostream成员函数处理的types之一,则不变)。 下面的例子似乎与上面的引用相矛盾。 根据上面的报价,我期待v的价值保持不变 – 但它被归零。 这种明显的矛盾行为的解释是什么? #include <iostream> #include <sstream> int main( ) { std::stringstream ss; ss << "The quick brown fox."; int v = 123; std::cout << "Before: " << v << "\n"; if( ss >> v ) { std::cout << "Strange — was successful at reading a word into an […]

重置一个stringstream

如何将stringstream的状态“重置”到创build时的状态? int firstValue = 1; int secondValue = 2; std::wstringstream ss; ss << "Hello: " << firstValue; std::wstring firstText(ss.str()); //print the value of firstText here //How do I "reset" the stringstream here? //I would like it behave as if I had created // stringstream ss2 and used it below. ss << "Bye: " << secondValue; […]

为什么不推荐使用std :: strstream?

我最近发现std::strstream已被弃用,而std::stringstream 。 我已经使用了一段时间,但是当时做了我需要做的事情,所以很惊讶听到它的贬低。 我的问题是为什么做出这个决定, std::stringstream提供了std::strstream中缺less的好处吗?

Qt c ++聚合“标准::串streamSS”具有不完整的types,无法定义

我有我的程序中的整数转换为string的函数: QString Stats_Manager::convertInt(int num) { stringstream ss; ss << num; return ss.str(); } 但是,当我运行这个我得到的错误: aggregate 'std::stringstream ss' has incomplete type and cannot be defined 我不确定这是什么意思。 但是,如果你现在如何解决它或需要更多的代码,请只是评论。 谢谢。

不完整的types是不允许的:stringstream

为什么这行给出错误Error: incomplete type is not allowed ? stringstream ss;

如何将string转换为C ++中的string?

如何从C ++中将std::stringstream转换为std::stringstream ? 我是否需要在stringstream上调用方法?