如何在c ++中epur一个std :: string?

kle*_*vre 1 c++ string algorithm

我会知道在没有使用boost的情况下使用std :: string的最佳方法和最简单的方法.

例如,如何转换此字符串

"  a   b          c  d     e '\t' f      '\t'g"
Run Code Online (Sandbox Code Playgroud)

"a b c d e f g"
Run Code Online (Sandbox Code Playgroud)

假设'\ t'是正常制表.

谢谢.

Ker*_* SB 6

使用字符串流的懒惰解决方案:

#include <string>
#include <sstream>

std::istringstream iss(" a b c d e \t f \tg");
std::string w, result;

if (iss >> w) { result += w; }
while (iss >> w) { result += ' ' + w; }

// now use `result`
Run Code Online (Sandbox Code Playgroud)