Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I need help to retrieve the user input

How can I read the user input at the console?

Example
Enter a number: 100
When I read by CIN>>, the cursor jump to the line below "Enter a number:" and I would like to read it at the same line like "Enter a number: 100" not
"Enter a number:
100*"


Thanks in Advance
Merh

What I have tried:

C#
Console(X, Y, "Enter a number:");


void Console(int X, int Y, string text)
{       string str;
	printf("\033[%d;%dH%s", Y, X, text.c_str());
        cin>>str;

}
Posted
Updated 15-Dec-16 7:32am
v3
Comments
[no name] 15-Dec-16 10:15am    
"How can I read the user input at the console?", you would use cin just like you are doing. But since you decided not to describe your actual problem and we can't read your mind.....
Richard MacCutchan 15-Dec-16 10:31am    
Since your string str does not contain any text, then your printf statement will likely kill your application.
Jochen Arndt 15-Dec-16 12:06pm    
You are already reading it into str.
But then you return from your function without using the variable.

1 solution

Google is your friend, many answers, try the solution on this one:

c++ - How do I input variables using cin without creating a new line? - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900