Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ memorystream-stringstream、string、其他?_C++_String_Stl_Stream_Buffer - Fatal编程技术网

C++ memorystream-stringstream、string、其他?

C++ memorystream-stringstream、string、其他?,c++,string,stl,stream,buffer,C++,String,Stl,Stream,Buffer,我正在通过常用的c++/STL/iostream语法读取二进制文件。 我将整个内容复制到一个动态分配的字符数组中,到目前为止效果很好 但由于我想把部分内容作为节目另一部分的台词, 我认为坚持使用流会更好/更容易,因为我不想到处乱闯 使用cstring函数和指针 我现在的问题是,如何将读取的内容存储在内存中。在一条小溪里?还是一串? 哪个更合适?两者之间有什么优点或缺点吗 提前谢谢 如果要将其作为流读取,不妨直接从文件读取到stringstream: std::stringstream data;

我正在通过常用的c++/STL/iostream语法读取二进制文件。 我将整个内容复制到一个动态分配的字符数组中,到目前为止效果很好

但由于我想把部分内容作为节目另一部分的台词, 我认为坚持使用流会更好/更容易,因为我不想到处乱闯 使用cstring函数和指针

我现在的问题是,如何将读取的内容存储在内存中。在一条小溪里?还是一串? 哪个更合适?两者之间有什么优点或缺点吗


提前谢谢

如果要将其作为流读取,不妨直接从文件读取到stringstream:

std::stringstream data;
data << input_file.rdbuf();
std::stringstream数据;

data ok,读取后复制很容易这(如果是真的)还声明stringstreams内部缓冲区是一个字符串(因此我猜它的名称)。我怎样才能为这个缓冲区保留字节?我在ctor中没有看到任何关于这个的注释,也没有看到任何关于保留函数的注释…谢谢,已经知道了。现在的问题是,在我的类中将stringstream存储为一种内存/字符缓冲区是否明智?或者我应该使用一个字符串?那么std::stringbuf呢?如果没有具体的原因,我只需要存储stringstream。