I am trying to make a playlist organizer as an exercise to learn more about i/o to files. I'm having lots of problems but the two I need help with is positioning where the program reads and writes from and strings with spaces.
I need the output to always start at the end of the file so it does not overwrite the past outputs to the file. I have looked at the reference here but I still don't know what to do. I then would have to reposition it at the begin to read from the file. Any help is greatly appreciated.
Another problem is that if someone inputs a string with more than one word it skips. Again, I'm clueless of what to do and any help would be gladly received.
I found a similar thread to the your first link but it didn't show the example which helped me solved it. Thanks :)
My actual problem with strings is not to do with i/o but simply writing to a string. When I write to a string with user input it skips it. Here's an example to explain what I mean:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
int main()
{
usingnamespace std;
string fullName;
cout << "What is your full name?\n> ";
cin >> fullName;
cout << fullName;
cout << "Press ENTER to exit\n";
cin.get();
cin.get();
return 0;
}
This doesn't work because everyone full name consists of at least two separate words. A song title can be a varying amount of word though so I need it to accommodate for that.
cout << "Song Title:\t\t";
getline (cin,song); //it prints out Artist before this line works
cout << "Artist:\t\t";
getline (cin,artist);
cout << "Album:\t\t";
getline (cin,album);
EDIT: When I put a breakpoint on the commented line above it skips it in the program.
EDIT: A further getline() got it to work although I have no idea why...