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 + "\"";
}
精彩评论