+ 1

c++ string that has a return value ?

how can i write a string with a return value . for example i will input a name . then the program will output the entered name and so on . i dont want my program will exit if i dont want to enter a value that is exit .

3rd Aug 2017, 9:06 AM
John Nehry C. Dedoro
John Nehry C. Dedoro - avatar
4 Réponses
+ 7
std::string var = ""; while (var != "exit") { std::cin >> var; std::cout << "Your input is : " << var << std::endl; }
3rd Aug 2017, 9:26 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
sir hatsy rei i tried it but it continuos showing my input i want my program tha i can input then show the output then stop then another input
3rd Aug 2017, 11:02 AM
John Nehry C. Dedoro
John Nehry C. Dedoro - avatar
+ 1
its working now sir thank you !
3rd Aug 2017, 11:05 AM
John Nehry C. Dedoro
John Nehry C. Dedoro - avatar
0
If you want to read the string from keyboard just use cin to read and store it in a variable and then cout or printf to print it to screen. I think there is a lesson for this in this app (but not 100% sure)
3rd Aug 2017, 9:10 AM
Fabian Ess
Fabian Ess - avatar