C++ Remove new line from multiline string

前端 未结 12 2355
暗喜
暗喜 2020-12-08 06:14

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

12条回答
  •  情歌与酒
    2020-12-08 06:45

    Here is one for DOS or Unix new line:

        void chomp( string &s)
        {
                int pos;
                if((pos=s.find('\n')) != string::npos)
                        s.erase(pos);
        }
    

提交回复
热议问题