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

Home Posts Topics Members FAQ

parse strings

1 New Member
Hi! I am not a C++ expert, please help me..im getting a little confused.
I'm using Vc++ 6 by the way.

I have this code to read from a text file:

Expand|Select|Wrap|Line Numbers
  1. #include <fstream.h>
  2. char line[100];
  3. void main()
  4.     {  
  5.        ifstream fin("test.txt");
  6.  
  7.         while( fin.getline(line, 100) ) 
  8.         {
  9.             cout << "read line: " << line << endl;            
  10.         }
  11.     }
my prob is how to parse "line" so that I can store the values that i needed.

For example, if test.txt has the following information,
35 6
I need to store 35 to an int variable, and 6 to another int variable.
or, if I got 344:5
just the same as above, but this time, separate by a colon, not a whitespace..

please help me out..im really lost :(

Thank you very much!
Mar 19 '07 #1
1 1434
Ganon11
3,652 Recognized Expert Specialist
Do you know the delimiter that will be used (a.k.a. do you know there will be a space in between these ints)? If so, you can search for the first occurance of the delimeter (in this case a space) and get the characters before that position. Once you have this, you can perform some simple arithmetic operators to find out what decimal numbers each character represents and form your number.

Alternatively, you could use the >> operator as if you were using cin to get the integer values.
Mar 19 '07 #2

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

Similar topics

22
872
by: Ram Laxman | last post by:
Hi all, I have a text file which have data in CSV format. "empno","phonenumber","wardnumber" 12345,2234353,1000202 12326,2243653,1000098 Iam a beginner of C/C++ programming. I don't know how to...
19
20554
by: linzhenhua1205 | last post by:
I want to parse a string like C program parse the command line into argc & argv. I hope don't use the array the allocate a fix memory first, and don't use the memory allocate function like malloc....
46
12490
by: vvk4 | last post by:
I have an excel spreadsheet that I need to parse. I was thinking of saving this as a CSV file. And then reading the file using C. The actual in EXCEL looks like: a,b a"b a","b a,",b In CSV...
5
12614
by: Adam Klobukowski | last post by:
Hello I need to convert some strings int doubles. Unfortunetly strings do not follow my country culture standarts (we use , to separate decimal from fraction, but strings use . there etc.). ...
2
4827
by: Peter Kirk | last post by:
Hi there I would like some help with parsing date strings to DateTime structures. I can see that DateTime has Parse and ParseExact methods - but I am not sure what is best for me to use, and...
8
5016
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and I need to parse strings that look similar to the one below. All 5 rows will make up one string. I have a form where a use can copy/paste data like what you...
3
20626
by: aaronwmail-usenet | last post by:
Ok, I've seen many examples of javascript parsing an XML document retrieved from a file indicated by a URL. The problem is I need to parse (usually small) xml *strings* embedded in the...
5
3663
by: Navid Azimi | last post by:
What's the best way to parse a currency string to a decimal given the possibility of multiple currencies? That is, my numeric string can be ($12.00) or -£12.00; in either case I want -12.00 to be...
3
1953
by: starke1120 | last post by:
I have a table (tblVAS) that contains a field called VAS (Value Added Servies). This field is imported from an AS/400 and the filed contains several codes that relate to Value Added Services. The...
6
3502
by: Richard | last post by:
Which way would you guys recommened to best parse a multiline file which contains two fields seperated by a tab. In this case its the linux/proc/filesystems file a sample of which I have included...
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
7002
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
7205
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6887
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...
1
4910
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3085
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
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.