小编ebe*_*ebe的帖子

如何在C++中使用remove命令删除句子中的空格?

我得到一个文件作为输入,我读这样的第一行(引号标记开始和结束,但不在文件中):

"      1,     2.0,     3.0,     4.0                         "
Run Code Online (Sandbox Code Playgroud)

当我像这样使用remove命令时:

    astring = line;
    cout << endl << "Before trim: " << line << endl;
    remove(astring.begin(), astring.end(), ' ');
    cout << endl << "After trim: " << astring << endl;
Run Code Online (Sandbox Code Playgroud)

我得到的输出为:

1,2.0,3.0,4.02.0,    3.0,     4.0
Run Code Online (Sandbox Code Playgroud)

我只需要输出1,2.0,3.0,4.0.这里有什么问题?

c++ string stl trim erase-remove-idiom

4
推荐指数
1
解决办法
309
查看次数

标签 统计

c++ ×1

erase-remove-idiom ×1

stl ×1

string ×1

trim ×1