how to get input in array i a single line

(not convensional method i.e in the next line) in C++

Page 1 of 1

5 Replies - 15426 Views - Last Post: 20 November 2008 - 02:25 PM Rate Topic: -----

#1 arsihbk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

how to get input in array i a single line

Posted 16 November 2008 - 09:43 AM

Hey iv made a 3x3 Matrix calculator Program in VC8++.


The problem is that when i try to input value from user to an array, the curser goes down.

like this :

please enter values for matrix 1:
1
2
3
4
5
6
7
8
9

where as i need to get input in the same line.
Like this :

please enter values for matrix 1:
1 2 3
4 5 6
7 8 9


can any1 help me????????

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: how to get input in array i a single line

#2 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,120
  • Joined: 22-February 08

Re: how to get input in array i a single line

Posted 16 November 2008 - 09:49 AM

How about showing us the code?
Was This Post Helpful? 0
  • +
  • -

#3 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: how to get input in array i a single line

Posted 16 November 2008 - 10:20 AM

Have them enter each "line" at a time and parse it as such.
Was This Post Helpful? 0
  • +
  • -

#4 Gloin  Icon User is offline

  • Expert Schmexpert...
  • member icon

Reputation: 235
  • View blog
  • Posts: 4,489
  • Joined: 04-August 08

Re: how to get input in array i a single line

Posted 16 November 2008 - 10:50 AM

If you want the user to be able to input all numbers on one line then you need a way to separate the numbers. You can write a function to do this, but it takes a bit of time to develop that sort of function. You could read the input as a string and separate on blanks for example.
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3101
  • View blog
  • Posts: 19,141
  • Joined: 14-September 07

Re: how to get input in array i a single line

Posted 16 November 2008 - 11:19 AM

getline(cin, string, " "); //etc...



edit: don't forget to flush out crap that builds up in the stream

cin.ignore(); //single clog

//or

cin.sync(); //multiple char removal if its there


This post has been edited by KYA: 16 November 2008 - 11:37 AM

Was This Post Helpful? 0
  • +
  • -

#6 arsihbk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 16-November 08

Re: how to get input in array i a single line

Posted 20 November 2008 - 02:25 PM

View PostKYA, on 16 Nov, 2008 - 10:19 AM, said:

getline(cin, string, " "); //etc...



edit: don't forget to flush out crap that builds up in the stream

cin.ignore(); //single clog

//or

cin.sync(); //multiple char removal if its there




Thanks KYA for the code, ill try it asap i get free from my laptop.

:)

then i will give u feed back.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1