Jump to content
357mag

How to get the quotation marks to show

Recommended Posts

I want to print a line of text using cout but there is a word that I want to have quotation marks around it. I want the output to look like this:

 

Looking for the index position of the word "own".

 

What I've tried so far has not worked.

 

Here is what I got currently:

 

int main()
{
    string sentence = "To thine own self be true";
    string word = "own";

    cout << "The sentence is: " << sentence << endl;
    cout << "Looking for the index position of the word \"own\";

    cout << sentence.find(word) << endl;

    system("pause");
    return 0;
}

 

Share this post


Link to post

For the benefit of others who will read this discussion in the future...

 

You are simply missing the closing outer quote:

 

cout  << "Looking for the index position of the word \"own\"":

 

You might also consider using your word variable:

 

cout  << "Looking for the index position of the word \"" << word << "\"";

 

Also note that C++14 and later has std::quoted:

 

cout  << "Looking for the index position of the word " << std::quoted(word);

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×