Hey guys, I am new to the c++ world. Since today i've done all my work with simple shell scripting using gawk and sed. But the work i have to do takes way to long, so i want to learn C++.
And now I am sitting in front of my first problem and i cant find an answer to solve the problem.
I have to work with files in the form:
0100000001000000001100000000
0000000001000000001100000000
0001000100101000000000010001
0001000000100000000000010001
1111000010100111100000010001...
only much longer, up to 900mb per file.
But first for a unknown length per line and a given number of lines.
For the first steps i made small files with 100 lines and a line-length up to 200.
I wanted to safe these data in a 2D array, than add up the content of every column and safe it to a new array.
so in this example it would be:
1213000112301111102200030003
But theres my
mainproblem for the moment, if i read in the data and try to safe it to an 2D array, the program reads the whole line and puts it into one point of the array (f.e.: arr[1][1]= 0100000001000000001100000000) instead of put every char of the line in one separated point of the array like:
arr[1][1]=0
arr[1][2]=1
arr[1][3]=0
arr[1][4]=0
I've written:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
int samplesize = 100; // should be given by user, only for testing
int samplelength = 200; // should be detected automatic, only for testing
int main ()
{
int numlines, numlines_beta = 0;
ifstream tin("testfile_small.msms");
while ( tin.good() ){
std::string line;
std::getline(tin, line);
++numlines_beta;
}
numlines = (numlines_beta-1);
cout << numlines << endl;
string paket_array[numlines][500];
int plus1 = 0;
ifstream band("testfile_small.msms");
while ( band.good() ){
for (int baat = 0; baat <= numlines-2; baat++) {
std::string line;
std::getline(band,paket_array[baat][plus1], '\n');
plus1++;
}
cout << paket_array[300][plus1-50] << endl;
}
return 0;
}
| |
This code may contain useless stuff, but i cut it out of a quite bigger content of fail-code.
Maybe i am just to stupid, but i thought that every single char would get stored in a separate place and not a whole line.
Hope u can help me.
PS: sorry for my bad english :D
I hope it won't kill u !