Sunday, August 2, 2009

In C++, how do you print quotation marks with an string in the middle?

For example:


I want to print:


" Blah blah blah "





Blah blah blah is a string.





it won't work like this:


cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\" %26lt;%26lt; movieName \"" %26lt;%26lt; endl;

In C++, how do you print quotation marks with an string in the middle?
It looks like your line should be like this:





cout %26lt;%26lt; "Movie name: " %26lt;%26lt; setw (30) %26lt;%26lt; "\"" %26lt;%26lt; movieName %26lt;%26lt; "\"" %26lt;%26lt; endl;





You need to use "\"" when you want a string that just contains a double-quote character
Reply:I thought that \" worked.
Reply:Your code not work becuse you must write:


cout %26lt;%26lt; "Movie name:" %26lt;%26lt; setw(30) %26lt;%26lt; "\"" %26lt;%26lt;moveName "\"" %26lt;%26lt;endl;


an other example:


to output : Blah "BLAH" blah


you must write:


cout%26lt;%26lt;"Blah \"BLAH\" blah";


No comments:

Post a Comment