So I'm working on a basic C++ payroll program, but I'm having trouble getting the getline() function to work properly. It's supposed to read from a plain text file an employee's ID number, name, payrate, and the number of dependents and store them into 5 separate variables. So the information in the text file is formatted as follows:
012 James Baker 13.50 2 M
015 Marianne Verince 15.00 1 F
etc.
That last piece of data is the employee's gender, but that can be ignored easily enough so I'm not concerned with that. In any case, I'm using the following line of code to call the getline function (inputFile represents the text file being read in, declared via ifstream):
inputFile.getline(id, 3) ;
That should, according to what I know in any case, get the first three characters of the line (or until a newline character is reached) and store into the 'id' variable...which it does -- only it's storing in a character array and converting it, which is the problem I'm having. I've also tried static_casting it, but that doesn't seem to work either as I get the same warning regarding an undesired conversion.
So that's essentially it. A basic C++ problem...any help is tremendously appreciated and I'll be more than happy to clarify if anyone that can help needs it.
012 James Baker 13.50 2 M
015 Marianne Verince 15.00 1 F
etc.
That last piece of data is the employee's gender, but that can be ignored easily enough so I'm not concerned with that. In any case, I'm using the following line of code to call the getline function (inputFile represents the text file being read in, declared via ifstream):
inputFile.getline(id, 3) ;
That should, according to what I know in any case, get the first three characters of the line (or until a newline character is reached) and store into the 'id' variable...which it does -- only it's storing in a character array and converting it, which is the problem I'm having. I've also tried static_casting it, but that doesn't seem to work either as I get the same warning regarding an undesired conversion.
So that's essentially it. A basic C++ problem...any help is tremendously appreciated and I'll be more than happy to clarify if anyone that can help needs it.