内存流 - 字符串流,字符串,其他?
我正在通过通常的 c++/STL/iostream 语法读取二进制文件。 我正在将整个内容复制到动态分配的字符数组中,到目前为止效果很好。
但由于我想将部分内容作为程序另一部分的线路提供, 我认为坚持使用流会更好/更容易,因为我不想乱搞 使用 cstring 函数和指针。
我现在的问题是,如何将读取的内容存储在内存中。在字符串流中?或者在字符串中? 哪个更适合?其中一种相对于另一种有什么优点或缺点吗?
提前致谢!
i am reading in a binary file via the usual c++/STL/iostream syntax.
i am copying the whole content into an dynamically allocated char array and this works fine so far.
but since i want to serve parts of the content as lines to another part of the program,
i think it would be better/easier to stick to streams because i don't want to hack around
with cstring functions and pointers.
my question now is, how can i store the read in memory. in a stringstream? or in a string?
which fits better? are there any advantages or disadvantages of one over the other?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想将其作为流读取,您也可以直接从文件读取到字符串流:
这会将“input_file”的全部内容读取到“data”中。您可以像读取任何其他流一样从那里读取数据。
If you want to read from it as a stream, you might as well read directly from the file to the stringstream:
That reads the entire contents of 'input_file' into 'data'. You can read the data from there like you would any other stream.