I'm a little lost with C++ so I could really use your help with this one! I googled it but nothing does what I want to do!
So here is my problem...
Let's say I have a file like this:
A 10 20 30 40
B 25 13 100 99
C 2 5 4 20
and I take one line at a time...
I want to create an array with A, B, C in it. I did it! But now I want to create an int array that will look like this:
10 20 30 40
25 13 100 99
2 5 4 20
Post the code how you got the first part to work. In the second part, create a 2d array of integers and read each integer one at a time using cin's >> operator (that's why I want to see your first code so that I can see how you are reading the file).
cout<<"Pliktrologeiste 3ana tin entoli dinontas 8etikous akeraious apo 1 ews kai 100 ws suntetagmenes!";
while ((entoli[a]==' ')||(entoli[a]=='\t'))
the !!!!!!! part is where I actually do it... the rest is some things I do before. I just have to do them to find the letter. don't mind the greek sentences. let's also say that rectangles are ten or less. so the 2D array has to be . It's 4 because I will be given 4 numbers for it's rectangle.
What are you trying to do with find()? There is no decimal in the sample input. If numerical values are restricted to positive ints, as posted, there is no dash either.
Read in an entire line at once using cin and use a stringstream object to break out the pieces and then store them however you want to:
const int MAXLETTERS]
const int MAXROW = 2;
const int MAXCOL = 2;
int index = 0;
getline(cin, entoli); //input is A 10 20 30 40 and is stored as STL string object
stringstream ss(entoli); //create a stringstream object using the input
ss >> letters[index++]; //obtain the letter
//get the numbers
for(int i = 0; i < MAXROW; ++i)
for(int j = 0; j < MAXCOL; ++j)
ss >> numbers[i][j];
Alternatively, read in each piece separately, in this example from a file called myFile using an ifstream. Assumes file is predictably delineated, in the case posted, using whitespace, and each line has 1 char and 4 ints per line;
int i = 0;
const int MAXLETTERS = 4;
const int MAXROW = 4;
const int MAXCOL = 4;
int i= 0;
while(i < MAXROW)
while (fin >> letter[i])
for(j = 0; j < MAXCOL; ++j)
fin >> numbers[i][j];