Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++
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 1-Jan-13 21:59pm
Comments
Zoltán Zörgő at 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 at 2-Jan-13 4:16am
   
You already asked this yesterday: http://www.codeproject.com/Questions/519385/arrayplusintoplusmultipleplusarrays
CPallini at 2-Jan-13 4:24am
   
Why do you need that? Please elaborate.
Richard MacCutchan at 2-Jan-13 4:57am
   
Why not create the individual arrays as you read the file?
Sith Indunil at 2-Jan-13 7:39am
   
well @Cpallini cz nothing worked for me..... i tried several ways but nothing worked..

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Something similar to this might work for you;
 
#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
  Permalink  
Comments
jibesh at 2-Jan-13 6:23am
   
nice Answer!!
+5
Sith Indunil at 2-Jan-13 7:38am
   
thanks Fredrik :D
Fredrik Bornander at 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)

  Print Answers RSS
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,490
2 CPallini 5,310
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 2 Jan 2013
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