-2

I have gone through other StackOverflow questions but what i need is little different. I have a long string (probable from some word document) and i want to count the number of characters of the string. I am copying that long string in my code string s3=<paste the string here> How do i proceed ahead. I dont need a solution in C++11.

#include<iostream>
#include<string>

using namespace std;

int main()
{

    string s1="My test"; //Works
    string s2="My" "test"; //Still works
    string s3="My"1003"test"; //Doest work. My string being input from user is `My "1003" test`. If i input it in string it becomes "My "1003" test.
    cout<<s;
}

Edit : Read the question first adn try to understand what is the catch here instead of blindly suggesting as duplicate. Escaping the character is not handy as the string might comtain a lot of doublw quotes and manually using escape character for double quotes is not handy.

anurag86
  • 1,635
  • 1
  • 16
  • 31
  • 1
    How are you reading the string? Post a complete example that actually compiles. – user657267 Feb 10 '16 at 08:12
  • 2
    Possible duplicate of [How to get double quotes into a string literal?](http://stackoverflow.com/questions/12338818/how-to-get-double-quotes-into-a-string-literal) – Pierre Feb 10 '16 at 08:13
  • Double quote is just a regular single-byte character, I don't see any reason to have issues with in on the input. – Dmitry Grigoryev Feb 10 '16 at 08:14
  • 1
    Is this about strings that are entered by the user during runtime or about string litterals in your sourcecode? Escaping is only necessary for string litterals in your sourcecode – MikeMB Feb 10 '16 at 08:21

1 Answers1

0

If you want to enter a string in your source code that has a " in it, you need to escape it as \".

Example: "My\"1003\"test" is a string containing the letter 'M', the letter 'y', a quotation mark, the digit 1, and so on.

user253751
  • 57,427
  • 7
  • 48
  • 90