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).
Ancient Dragon
Achieved Level 70
32,275 posts since Aug 2005
Reputation Points: 5,852
Solved Threads: 2,591
Skill Endorsements: 70
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:
string entoli;
const int MAXLETTERS]
char letters[MAXLETTERS];
const int MAXROW = 2;
const int MAXCOL = 2;
int numbers[MAXROW][MAXCOL];
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;
int j;
const int MAXLETTERS = 4;
const int MAXROW = 4;
const int MAXCOL = 4;
int i= 0;
char letters[MAXLETTERS];
int numbers[MAXROW][MAXCOL];
ifstream fin("myFile");
while(i < MAXROW)
{
while (fin >> letter[i])
{
for(j = 0; j < MAXCOL; ++j)
fin >> numbers[i][j];
}
++i;
}
Lerner
Nearly a Posting Maven
2,408 posts since Jul 2005
Reputation Points: 739
Solved Threads: 406
Skill Endorsements: 9