Hello all, I am a long time browser and first time poster here. Right now I am a little stuck on my project and could use a little help.
The program opens a .txt file and then reads the data and places the data accordingly. The issue this time compared to most times is that the items I am trying to send to a string have spaces in them. (firstname lastname, adress, phone) So, I am not able to use the regular:
inFile >> name[i] >> address[i] >> phone[i];
Is there anyway I can get this information in from the file as a string or do I have to use a c-string? I have also tried what I have below but the artist outputs everything after instead of only until the location of the double space.
while (!inFile.eof())
{
pos = 0; // Sets position to start
inFile.getline(line, 100); // Receives first line as full c-string
tempStr = string(line); // Sets line to a temp string
ds1 = tempStr.find(" ", 0); // Finds first double space position after title
title[ptr] = tempStr.substr(pos, ds1); // Sets title to substring before double space
pos = 37; // Sets position to artist
ds2 = tempStr.find(" ", pos); // Finds first double space position after artist
artist[ptr] = tempStr.substr(pos, ds2); // Sets artist to substring before double space
cout << title[ptr] << " " << artist[ptr]; // Test output
cout << endl;
ptr++;
}
Thanks for any help possible.