Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
i want to read data from a file... and store in separate string arrays. i know how to read the whole file into one array. but i need to read 10 lines and store in one array and another 10 lines and store in another array.. likewise 8 times.please help Smile | :)
Posted 25-Dec-12 5:07am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

well, if new line is the indicator of your one line, then count 10 new line, when you would reach the 10th new line you will start storing in your next array.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi there,
 
use getline api and read the each line from the file and maintain the count to read the lines from file.
if counts reach 10 means stop adding into first CStringArray. If the count starts 11, so start adding into another CString Array.
 
like wise you can split.
 
regards
Ranjith
  Permalink  
Comments
Sith Indunil at 26-Dec-12 5:49am
   
but still i used getline function inside a for loop: and can i use if statement to check the incriment and give anothe array? eg: if(a > 11 && a < 22)
ranjithkumar81 at 26-Dec-12 6:21am
   
for example:
declare int count variable in global;
open the file
if(file Handle != NULL)
do
{
read the line from file
add lines into CString array
count++;

if(count == 11)
add the lines(data) into another array
else if(count == 21)
add the lines(data) into another array
else if(count == 31)
add the lines(data) into another array
else
add the lines(data) into another array.
 
}while(fileHandle != EOF)
 

You may try this method....
Sith Indunil at 1-Jan-13 0:57am
   
while( !lo.eof())
{
getline(lo,arr1[i]);
 
if( i == 11)
{
getline(lo,arr2[i]);
}
 
else if( i == 22)
{
getline(lo,arr3[i]);
}
 
else if( i == 33)
{
getline(lo,arr4[i]);
}
 
else if( i == 44)
{
getline(lo,arr5[i]);
}
 
else if( i == 55)
{
getline(lo,arr6[i]);
}

else if( i == 66)
{
getline(lo,arr7[i]);
}
i++;
}
 

this thing doesnt work :/ any idea?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 450
1 OriginalGriff 220
2 DamithSL 130
3 Dave Kreskowiak 120
4 Suvendu Shekhar Giri 110
0 OriginalGriff 7,645
1 DamithSL 5,614
2 Sergey Alexandrovich Kryukov 5,344
3 Maciej Los 4,961
4 Kornfeld Eliyahu Peter 4,539


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 26 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100