开发者

C++ cin: don't show the newline

If I get some value by using getline( cin, myStr ); a newline is printed after the information the user entered - logically as he pressed enter:

Please enter something: ABC <enter =&开发者_如何学Pythongt; \n>
This text is printed out by the program and should be in the same line as before
  • How to keep the newline after user input away?

I'm using MSVC 2010 and build a simple console app using iostream and string as main libraries.


You can't - the newline processing isn't controlled by the C++ program. What you can do is use the Windows console APIs to reposition the cursor after the input. Or use those APIs to write your own version of getline().


You can't do this using just standard C++. I'd recommend looking at PDCurses, which is a Windows-compatible replacement of NCurses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜