Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
have a string array which keeps data which read from a file. it consists 70 lines.

what i want to do is store those in different arrays. like from 21st line to 31st line in 1 array. and 31st to 41st one array. how can i do it... plz help

i want to split 70 lines into 7 arrays each containing 10 lines of it. and do it without using vectors
Posted
Comments
Zoltán Zörgő 2-Jan-13 4:04am    
1) "and do it without using vectors" - why exactly?
2) This looks very simple, what have you tried so far?
3) The number of rows and arrays is constant?
Graham Breach 2-Jan-13 4:16am    
You already asked this yesterday: http://www.codeproject.com/Questions/519385/arrayplusintoplusmultipleplusarrays
CPallini 2-Jan-13 4:24am    
Why do you need that? Please elaborate.
Richard MacCutchan 2-Jan-13 4:57am    
Why not create the individual arrays as you read the file?
Sith Indunil 2-Jan-13 7:39am    
well @Cpallini cz nothing worked for me..... i tried several ways but nothing worked..

1 solution

Something similar to this might work for you;

C++
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main (int argc, const char* argv[])
{
    // Read the lines
    string lines[70];
    fstream file("C:\\Temp\\file.txt");
    string line;
    int index = 0;
    while(getline(file, line) && index < 70)
    {
        lines[index++] = line;
    }

    // Split the lines across arrays of ten lines each
    string splitLines[10][10];
    for(int i = 0; i < index; ++i)
        splitLines[i / 10][i % 10] = lines[i];

    return 0;
}


Hope this helps,
Fredrik
 
Share this answer
 
Comments
Jibesh 2-Jan-13 6:23am    
nice Answer!!
+5
Sith Indunil 2-Jan-13 7:38am    
thanks Fredrik :D
Fredrik Bornander 2-Jan-13 8:00am    
Glad I could help.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900