357mag 3 Posted Saturday at 04:04 AM 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
Remy Lebeau 1451 Posted Saturday at 04:51 PM (edited) 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 the std::quoted stream manipulator: #include <iomanip> ... cout << "Looking for the index position of the word " << std::quoted(word); Edited Saturday at 10:46 PM by Remy Lebeau Share this post Link to post