Good evening folks. I'm in the design phase of writing a program. The portion where I'd like feedback is if I'm trying to read from an input file that has the following structure:
CS04 John Baldwin
and I want to break this up into 2 arrays. The first array would contain just CS04 and the 2nd array would contain John Baldwin as a concatenated string.
To do this would I use cin>> and a nested while loop? Here's my algorithm so far. Comments are appreciated.
-----------
eclare a local variable char stuID in order to accept the Student ID and numS to count
number of students as well as the index of the array
Initialize numS = 0;
Using an outer sentenial controlled while loop to read the first string of information
with the sentenial being the ability to cin.
Use the cin >> to read the first set of string characters as place into the idArray[stuID]
and increment numS.
Declare local variables string firstName, string lastName, string name.
Use an inner sentenial controlled while loop with the sentential being the new line character
Use cin >> firstName >> lastName.
Create string name by concatenating firstName + ' '+lastName
So, you just need two strings?
Just read the whole line into a string, std::string::find() the first ' ' (we'll call the result pos) and split the string into [0;pos) and [pos+1;n).