一、清空误区
清空stringstream,应该用 .str(""),用clear()是无效的,clear清空的是stream的状态(比如出错状态)
二、进制转换
#include <string>
#include <sstream>
#include <iostream>
int main()
{
std::stringstream stream;
std::string result;
int i = 1000;
stream << i; //将int输入流
stream >> result; //从stream中抽取前面插入的int值
std::cout << result << std::endl; // print the string "1000"
}
本文介绍了C++中stringstream的正确使用方法,澄清了清空stringstream的常见误区,并演示了如何利用stringstream进行数值到字符串的转换。
9481

被折叠的 条评论
为什么被折叠?



