开发者

Double Quoted Strings in C++

How to converted string with space in double quoted string. For Example: I开发者_如何学编程 get string

c:\program files\abc.bat

I want to convert this string to "c:\program files\abc.bat" but only if there is space in the string.


Assuming the STL string s contains the string you want to check for a space:

if (s.find(' ') != std::string::npos)
{
  s = '"' + s + '"';
}


Search for white spaces. If found add \" to the front and the end of the string. That would be an escaped quotation mark.


std::string str = get_your_input_somehow();

if (str.find(" ") != std::string::npos) {
  str = "\"" + str + "\"";
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜