[Solved] How to save ” in a string in C++?


You will need to escape the quotation mark you require in the string;

std::string str("Q850?51'18.23\"");
//                            ^ escape the quote here

The cppreference site has a list of these escape sequences.

Alternatively you are use a raw string literal;

std::string str = R"(Q850?51'18.23")";

The second part of the problem is dependent on the format and predictability of the data;

  • If it is fixed width, a simple index and be used to extract the numbers and convert to the double you require.
  • If it is delimited with the characters above, you can consume the string to each of the delimiters extracting the numbers in-between them (you should be able to find suitable libraries to assist with this).
  • If it is some further unknown composition, you may be limited to consuming the string one character at a time and extracting the numerical values between the non-numerical values.

solved How to save ” in a string in C++?