|
-
Nov 16th, 2001, 12:55 PM
#1
Thread Starter
New Member
Read Lines from a file and split each one
Hi
I am new to C++ and I want to write a programm that reads lines from a file into character arrays and then splits them (the arrays) into two parts. The first part is before the delimeter (usually " ") and the second after it. The file is consisted of eleven lines. The first is a number that must be stored in a k variable. The 10 remaining have 2 numbers each and the numbers are divided by a space (" ")
e.g
---Start of file-----
5
2 12
3 45
1 20
5 34
7 29
8 84
10 28
9 14
---End of file-----
Total eleven lines
Here's how I think the code should be. Please help me fill in the missing parts of the loop
int k;
ifstream b_file("input.txt");
b_file>>k;
//The above part reads the first number and stores it in k var
for (i=1; i<=10; i++)
{
//The code in here must input Line of file into Line[i] string
//the code in here must split Line[i] into TempA[i] (this is the first number of the line) and TempB[i] (this is the second number of the line) with " " as the delimeter
}
b_file.close();
Thanks for your help
Wh1t3w0lf
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|