最好使用std :: string或std :: stringstream [英] Better to use std::string or std::stringstream
问题描述
我有一个"printf"样式功能:
Hi,
I have a "printf" style function:
void myclass::write (int, char *, ...)
此函数采用通常的printf样式参数.我正在执行的转换是使用简单的vsprintf.字符串转换后,需要将其存储以供以后打印(通过std :: cout接口).字符串转换后,将不再对其进行任何处理.它们只是打印出来的.
1.将字符串存储在std :: string中更好吗?
2.将字符串存储在std :: stringstream中更好吗?
3.是否有更好的存储空间?
谢谢.
This function takes the usual printf style params. The conversion I am doing is using the simple vsprintf. After the string is converted, it needs to be stored for later printing (through a std::cout interface). After the strings are converted there is no more processing done on them; they are just printed.
1. Is it better to store the strings in std::string?
2. Is it better to store the strings in std::stringstream?
3. Is there a better storage for this?
Thanks.
推荐答案
由于只需要存储一个字符串,请使用std::string
.
Since you only need to store a string, use std::string
.
这篇关于最好使用std :: string或std :: stringstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!