Hello, I am fairly new to C++ and am having a bit of trouble reading in a text file to my program which contains numbers(integers) and names(strings) and checking for spaces in the names(strings).I basically am reading in a .txt file which contains numbers and letters. In this file, the numbers correspond to a dogID number and the letters correspond to the name of the dog.Now the problem....
The string containing the dog names needs to be able to have spaces. The code needs to check for spaces and then for integers. If the name(string) is complete, the code needs to proceed to the dogID number(integer). So basically, I need to load a string, then load an integer, load a second string, then load a second integer and so on...
The code below is something that I came up with but am having trouble implementing it. It checks for ASCII characters 47-58(which are numbers 0 through 9 in the ASCII table) and then a conversion from string to integer is needed. Maybe string1 and string2(dog names) should be appended? Will the built in atoi function be useful here? Thanks in advance.
bool isString = true;
string Dogname = " ";
int trash;
while (isString = true)
{
trash = " ";
strcat(Dogname, trash);
}
if(atoi(trash(0)) >> 47 && atoi(trash(0)) < 58)
{
readin >> trash;
//convert string to integer?
}
else
{
//convert string to int?
// push back to next dog name and integer(number)
}