我在C++ STL中不太好。 我有串狀:替換字符串中的空格
x ,y z , a ,b, some text ,
我想除了這兩個詞 所以我想輸出爲之間的空間被刪除在這一切的空間:
x,y z,a,b,some text,
我可以很容易做到這一點在Perl中:
perl -pe 's/\s*,\s*/,/g;s/^\s*//g'
但我需要它在C++中。
我所能做的到現在是:
line.erase(remove_if(line.begin(), line.end(), isspace), line.end());
但這刪除的行中的所有splaces。
我使用的編譯器:
> CC -V
CC: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25
不具有正則表達式頭
[boost](http://stackoverflow.com/questions/11321533/how-to-use-boost-regular-expression-r E放置方法)? – Dukeling
可能的重複http://stackoverflow.com/questions/5891610/how-to-remove-characters-from-a-string –
而這裏http://stackoverflow.com/questions/236129/splitting-a-string- in-c – doctorlove