5 Replies - 1590 Views - Last Post: 21 April 2012 - 09:45 PM Rate Topic: -----

#1 therry   User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 22
  • Joined: 25-June 11

Controlling the output of more than one cin>> statment

Posted 21 April 2012 - 03:27 PM

If I want to have code using C++ like:
 cin >> aa >> bb >> cc >> dd;


can I control its output such that the all the responses for *cin >> aa, bb, cc, dd are printed all on the same line, instead of the standard output where there is a '/n' after each >> response like:
x
x
x
x


I would like the output for
 cin >> aa >> bb >> cc >> dd;

to be like
 x  x  x  x


Is This A Good Question/Topic? 0
  • +

Replies To: Controlling the output of more than one cin>> statment

#2 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1270
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Controlling the output of more than one cin>> statment

Posted 21 April 2012 - 03:32 PM

Quote

instead of the standard output where there is a '/n' after each

std::cout will not place a new line character in the output stream after output.

std::cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd;


This post has been edited by jjl: 21 April 2012 - 03:33 PM

Was This Post Helpful? 0
  • +
  • -

#3 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2678
  • View blog
  • Posts: 4,277
  • Joined: 21-June 11

Re: Controlling the output of more than one cin>> statment

Posted 21 April 2012 - 03:37 PM

It shows up that way because you hit enter after every x. If you enter the input as "x[SPACE]x[SPACE]x[SPACE]x[ENTER]" it will show up with spaces instead of linebreaks.

The only way to change how the input appears on the screen even if the user keeps hitting enter after each x, would be to put the terminal into noecho mode (using non-ISO, system-specific functions) and then echo back the input yourself the way you want to (possibly reading the input character by character to echo back each character as soon as its typed).
Was This Post Helpful? 1
  • +
  • -

#4 jimblumberg   User is online

  • member icon

Reputation: 5611
  • View blog
  • Posts: 17,304
  • Joined: 25-December 09

Re: Controlling the output of more than one cin>> statment

Posted 21 April 2012 - 03:47 PM

Also posted here.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 therry   User is offline

  • New D.I.C Head

Reputation: 8
  • View blog
  • Posts: 22
  • Joined: 25-June 11

Re: Controlling the output of more than one cin>> statment

Posted 21 April 2012 - 05:04 PM

Thanks sepp2k,
You just took a load off my shoulders.
I didn't know that "Dream_in_code" was also "CProgramming"
Was This Post Helpful? 0
  • +
  • -

#6 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2254
  • View blog
  • Posts: 4,343
  • Joined: 30-May 10

Re: Controlling the output of more than one cin>> statment

Posted 21 April 2012 - 09:45 PM

But selfishly clogging up multiple forums with the same question in an effort to get speedy replies is frowned on for many reasons.
http://www.catb.org/...ions.html#forum
http://www.catb.org/...ons.html#urgent
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1