Help Using 1 Dimensional Arrays With a File That Contains Two Data Items

I am currently doing a programming project where a user has to interactively enter the name of a data file and then is presented a menu and choses a task to be executed. We are required to use 1 dimensional arrays to aid in the different tasks. The problem I am having is that the data file contains two different sets of data, the first item is an ID number, which is up to 6 digits long and does not start with a zero. The second item is a char and is either 'C', 'D', 'E', or 'R'. We are told that the data file contains 15 lines and is set up like the following:

1012 C
25 E
32441 R

and so on, until 15 lines is reached.

I have tried many things in order to just be able to set up the array and output the contents, but I am stuck because we can ONLY use 1D arrays. Could anyone provide some insight?

The code I am trying is as follows and the file has already been previously opened:

1
2
3
4
5
6
7
8
9
const int arraySize = 15;
int songId [arraySize];
int count = 0;
while (count < arraySize && inFile > songId[count])
    count++:
cout << "The data in the file is:";
for (count = 0; count < arraySize; count++)
  count << songId[count] << endl;


This code however, only gives me the first data structure, in this case 1012.

Thank you!
on line 8, you are using a shift operator on count, didn't you actually want to write cout?

Secondly, why not use inFile.get(), store the result in a char, check if the char is a white-space or not. If no whitespace, you're on the ID part, after a white-space has passed, you know now that the next .get() will return some letter.

Also, you'll need to put curly braces for your while. What you're currently doing is to ONLY count count++; until it becomes equal to arraySize, and nothing else.
I'm not going †☺ write the code but I'm just gonna drop some hint that will help you out.
Since you'll be dealing with a file, include an fstream.
Declare two arrays of type int and char.
While (not end of file):
1. input into first array of type int
2. input into first array of type char
Note: size of array must be more than or == length of file.
Topic archived. No new replies allowed.