C++ 字符串流输出比较
我想将stringstream的输出与一些字符串进行比较 问题是,当我在stringstream上使用填充和宽度时,我无法将生成的字符串与预加载的字符串进行比较C++ 字符串流输出比较,c++,stringstream,stdstring,C++,Stringstream,Stdstring,我想将stringstream的输出与一些字符串进行比较 问题是,当我在stringstream上使用填充和宽度时,我无法将生成的字符串与预加载的字符串进行比较 std::stringstream sstr; sstr.fill(' '); sstr.width(4); sstr << 4 << std::endl; if(" 4" == sstr.str()){ std::cout << "Equal" << std::endl;
std::stringstream sstr;
sstr.fill(' ');
sstr.width(4);
sstr << 4 << std::endl;
if(" 4" == sstr.str()){
std::cout << "Equal" << std::endl;
}
std::stringstream sstr;
sstr.填充(“”);
sstr.宽度(4);
sstr您还向字符串中插入了一个std::endl
。这将在字符串中添加一个换行符
从输出中删除std::endl
。您还在字符串中插入了std::endl
。这将在字符串中添加一个换行符
从输出中删除std::endl