473,322 Members | 1,473 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

No new line after cin

1
I am attempting to fill in values for a matrix and I am using cin to input number types such as int or float one at a time. Unfortunately, when I try to input numbers into a large matrix, usually larger than 4 by 4, it is harder to visualize the matrix when after each input, a new line is generated . How can I prevent a new line from being generated after a cin so I can then use spaces or '\t' to indicate another cin.

Any help appreciated.
Feb 18 '07 #1
2 6486
AdrianH
1,251 Expert 1GB
I am attempting to fill in values for a matrix and I am using cin to input number types such as int or float one at a time. Unfortunately, when I try to input numbers into a large matrix, usually larger than 4 by 4, it is harder to visualize the matrix when after each input, a new line is generated . How can I prevent a new line from being generated after a cin so I can then use spaces or '\t' to indicate another cin.

Any help appreciated.
Hi JasonV,

cin will automaticly seperate by whitespace. That includes carrige returns, tabs regular spaces and vertical tabs (which are hardly ever used). So if you read in 4 numbers in you code and the input has seperated some of those 4 numbers with carrige returns, then it doesn't matter, all 4 will be read.

What you need to do is detect if you have reached the end of the matrix. You could just read in numbers till the stream closes. You could use peek() to determine if there is something other than a number. There are probably other ways to do this too. The way you do it is up to you.

Hope this helps.


Adrian
Feb 18 '07 #2
Ganon11
3,652 Expert 2GB
You can also input your information 4 numbers at a time. If your prompt looked something like this:

Expand|Select|Wrap|Line Numbers
  1. Please enter your 16 values:
you can enter the numbers as:

Expand|Select|Wrap|Line Numbers
  1. Please enter your 16 values:
  2. 1 2 3 4
  3. 5 6 7 8
  4. 9 10 11 12
  5. 13 14 15 16
This should help you to visualize what's going on, and cin won't have any problems with this.
Feb 18 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Peter A. Schott | last post by:
Per subject - I realize I can copy/paste a line at a time into an interactive session when I'm trying to debug, but was wondering if there is any tool out there that allows me to copy sections of...
65
by: Skybuck Flying | last post by:
Hi, I needed a method to determine if a point was on a line segment in 2D. So I googled for some help and so far I have evaluated two methods. The first method was only a formula, the second...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
3
by: Double Echo | last post by:
Hi all, I'm using PHP 4.4.2, and use PHP on both the command-line and the web. I am running PHP on SuSE 10 Linux , in a VMware 5.5 workstation, using Apache 2.0.55 , on my Dell laptop. ...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
6
by: magix | last post by:
Hi, when I read entries in file i.e text file, how can I determine the first line and the last line ? I know the first line of entry can be filtered using counter, but how about the last line...
6
by: Jacob Rael | last post by:
Hello, I have a simple script to parse a text file (a visual basic program) and convert key parts to tcl. Since I am only working on specific sections and I need it quick, I decided not to...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
11
by: xdevel | last post by:
Hi, I don't understand option. if I write: #line 100 "file" I change file numeration to start to line 100 but what "file" ? any example?
19
by: =?Utf-8?B?QnJpYW4gQ29vaw==?= | last post by:
This is an example of the data; 2007/07/27 11:00:03 ARES_INDICATION 010.050.016.002 404.2.01 (6511) RX 74 bytes 2007/07/27 11:00:03 65 11 26 02 BC 6C AA 20 76 93 51 53 50 76 13 48...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.