473,498 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to take into account endline character in c++

1 New Member
Hello,

In c++ I need to read a file of the format

number (spaces) number (spaces) number
number (spaces) number (spaces) number

into an array/vector of the form array[length of file][3] where the amount of spaces between numbers is variable. I'm trying to do this using the getline function and reading in the numbers as strings but can't seem to make it loop so that on the end of the line it uses a '\n' instead of ' '. I've tried using an if-else combination of the form

Expand|Select|Wrap|Line Numbers
  1. if (j==2)
  2. {
  3.    y='\n';
  4. }
  5. else
  6. {
  7.    y=' ';
  8. }
  9.  and then placing y in the getline command 
  10.  
  11. for (i=0;i<=1;i++)
  12. {
  13.    for (j=0;j<=2;j++)
  14.    {
  15.       getline (cin,a[i][j],y);
  16.    }
  17. }

Furthermore how best to deal with the variable number of spaces, in this example i've only been using one space.

Thanks.
Mar 16 '07 #1
1 2552
Ganon11
3,652 Recognized Expert Specialist
If you just use the cin >> operator to get the number, it will skip any number of spaces and/or newline characters until it gets the next number. This will also save you the trouble of casting the string you get from getline into a number.
Mar 16 '07 #2

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

Similar topics

2
1431
by: Greg Buckley | last post by:
I have come across an interesting problem. Let me first state that I am not a fluent ASP programmer. I am a network engineering trying to port an existing app. The app in question is currently...
59
3395
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
9
7201
by: Andrew | last post by:
Apologies for the double-post.. I'm new, just getting used to this.. and should have posted this way in the first place.. How does one go about taking ownership of a registry key using C# & .NET...
1
1041
by: Li Pang | last post by:
I used MDI form. In the child form I set minimumsize, but it doesn't take account (the parent form does). Why? And how to set the minimumsize for the child? Thanks
1
1498
by: Ravi | last post by:
Hi, I want to use end line character('\n') in the XML Attribute like <message confirm=" This will kill your process . \n Are you sure to proceeed? "/> But in java xml processor, it is...
5
2226
by: lanclot | last post by:
hi i am trying to authenticate a user using ClientLogin by sending a post to https://www.google.com/accounts/ClientLogin in my c program use ssl and socket the next code is my request:...
5
14444
by: j.smith2c | last post by:
Hi everyone, I wanted to run the following loop, and enter y everytime (I expected that it will ask me to enter y for 5 time), but just after 3 times program terminates. what is the error?? ...
209
8574
by: arnuld | last post by:
I searched the c.l.c archives provided by Google as Google Groups with "word input" as the key words and did not come up with anything good. C++ has std::string for taking a word as input from...
0
918
by: Terry Reedy | last post by:
rishi pathak wrote: Does not work on Windows, at least with 3.0, as tty fails trying to import termios. There, use msvcrt module "msvcrt.kbhit() Return true if a keypress is waiting to be...
7
175
by: Lie Ryan | last post by:
>>I want to write something that handle every char immediately after its Don't you think that getting a one-character from console is something that many people do very often? Do you think that...
0
7125
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7004
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7167
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7379
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5464
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4593
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.