Post- cin Text? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Post- cin Text?

I have code that looks like this: void My_Character() { string char_name; cout<<“{Enter your character name: “ cin>>char_name; return; } How do I add the closing bracket “}” without it going to next line? I’ve tried cin.ignore(); but it still treats it as a return I have also tried cout<<“}” on line under cin but same result.. If it is relevant, my project is pretty lengthy in terms of code.

25th Feb 2019, 5:13 PM
Seij Bailey
Seij Bailey - avatar
3 Answers
0
I don't know what you want to achieve. where do you want to add the }? To the string char_name, then simply use the append of std::string. If you want it to be on the printed output, I didn't have the problem in my code: std::cout << "{Enter your name right now:"; std::string l_name; std::cin >> l_name; std::cout << "}" << std::endl << l_name;
25th Feb 2019, 5:35 PM
nobody
0
Did you add the ; in the cout-line? Does it compile without?
25th Feb 2019, 5:36 PM
nobody
0
nobody So I want the closing bracket to appear immediately after string name input. It wont be part of the variable, as the opening bracket is part of my cout statement. Like so cout<< “{Here is my bracket. Name goes here:___” cin>>name; // i want the closing bracket after this cin, however the following code is of course not legal: cin>>name<<“}”;
25th Feb 2019, 6:40 PM
Seij Bailey
Seij Bailey - avatar