Double quotes in C ++

How to convert a string with space to a double quote. For example: I get a string

c:\program files\abc.bat

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

+3
source share
3 answers

Assuming the STL sline contains the line you want to check for a space:

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

Search for spaces. If it is found, add "forward" and "end of line". This will be a shielded quotation mark.

+2
source
std::string str = get_your_input_somehow();

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

Source: https://habr.com/ru/post/1734058/


All Articles