357mag 3 Posted 12 hours ago 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 1448 Posted 7 minutes ago 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