C ++从多行字符串中删除新行 [英] C++ Remove new line from multiline string

查看:135
本文介绍了C ++从多行字符串中删除新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从std :: string中移除'换行符'最有效的方法是什么?

Whats the most efficient way of removing a 'newline' from a std::string?

推荐答案

#include <algorithm>
#include <string>

std::string str;

str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());

std :: remove的行为可能不是你期望的。请参阅此处的解释。

The behavior of std::remove may not quite be what you'd expect. See an explanation of it here.

这篇关于C ++从多行字符串中删除新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆