Kir*_*ran 2 c++ string stringstream
我需要逐步构建一个字符串,并试图找到最好的方法来做到这一点.它可以增长到的最大值是大约10k,因此计划做这样的事情:
const unsigned long long configSize = 10240; //Approximation
void makeMyConfig() {
std::string resp;
std::string input;
resp.reserve(configSize);
while ( getInput(input) ) {
resp += input;
}
if ( resp.length > configSize )
log << "May need to adjust configSize. Validate" << endl;
if (!sendConfig(resp)){
log << "Error sending config" << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
getInput可以从文件/ tcp conn或ftp读取,并在运行时决定.它接收const char*并将其放入一个字符串(我可以避免,但为方便起见)
但是,我听说有一种非常有效的方法来处理字符串流,但不知道该怎么做.欣赏任何见解.
Gra*_*rks 13
对我来说看起来很棒.
在实际出现性能问题之前不要进行优化,并且可以测量任何性能变化.如果没有意识到,你最终可能会变得更糟!
| 归档时间: |
|
| 查看次数: |
287 次 |
| 最近记录: |