Hi Chervil,
Thanks for the reply! We haven't thoroughly cover sstream, but would it be better to use stringstream with the code I've come up with so far?
1 2 3 4 5 6 7
|
getline(matrixFile, header,'\n'); //gets first line of matrix
header = eraseComma(header);// my erase comma function
cout << header << endl;
getline(matrixFile, matrixA, '\n'); //gets second line of matrix
matrix = eraseComma(matrixA);
|
-matrixFile is the file I have to read from
-header is the first line of the matrix (the line with no numbers)
-matrixA second line of the matrix (begins with A, 2, -2 etc.)
I then tried doing this
matrixStr << matrixA;
(matrixStr is variable of stringstream) but when outputting
matrixStr.str()
, it would still print out the original string with the negative signs detached. How would I actually go about attaching the negative signs using stringstream?
This would however, require to make a separate string for each line of the matrix. I have been trying to do it this way and it works for the most part, but is inefficient. However, most of the code I have written so far incorporates using 21 different strings.
But I also liked your idea about making three arrays/using a class. I did learn about classes, but I'm not exactly sure how I would create a function to an array of decode elements.
If I use three arrays, can the first array which will contain the repeating letter (in this case, A) be created by making a for loop run 21 times (the length of each line in the matrix) with each run inputting an 'A' into the array? (And then do this again for each letter)
And the second array with the top line of the matrix can be created by making two for loops, the outer loop running for as long as the length of the first array and the inner loop running for as long as the top line of the matrix.
The third array is where I am stuck. Would I create a for loop that starts at an index of [1] rather than [0], or am I totally going about this the wrong way?
I apologize in advance if this post is confusing.