How to Reset a text file to bof??
Hi,
I'm wondering how to reset a text file (ifstream infile("blah.txt")) to the beginning of the file using C++ (no C) after you've been working through it with some getline's.
From what I've read, it seems to be a bit easier to work with files in C using the FILE type and all the functions that go w/it but I really want to know how to do it in C++ with no old headers.
Thanks for your help.
Swaine777
Question about deleting...
Thank you for the advice about vectors & maps. Maps are really powerful if you know how to use them. :) I didn't really understand this chunk of code that you used to display the contents of the map/vector:
Code:
if( verseChoice <= Verses.size() && verseChoice != 0 )
{
ostream_iterator<string> osit(cout,"\n");
copy(Verses[verseChoice].begin(),Verses[verseChoice].end(),osit);
}
My C++ books are too elementary to have more advance STL stuff like this. I can only guess about the declaration of the ostream_iterator and the copy line. Declare an ostream_iterator that iterates through strings called "osit" that displays the contents of the output stream as it iterates and uses the newline char as the delimiter? Copy from the beginning of the chosen vector within the map to the end of the vector . . . to osit, an ostream_iterator which is set up to display it's contents line by line. How'm I doin'?
I was wondering, how to delete a vector from the map and rewrite the text file with the new map? I've been trying to figure it out by myself but I keep scratching my head trying to figure out what next.
Oop, 1 other thing...I'm trying to figure out how to get rid of the pipe after the search when I display the verse that was found.
Thanks for all your help.
Swaine777
more questions about this proggie
Hi again,
I've been working on implementing the suggestions you made for my program concerning maps and vectors and I realized that I don't know how to access the elements of the vectors within the map...
Code:
cout << "Rewriting verse file...\n\n";
int count = 0;
for(itVerses = Verses.begin(), itVerses != Verses.end(), itVerses++)
{
for(vit = Verses[count].begin(), vit != Verses[count].end(), vit++)
{
if(Verses[count] //scratch head here
I made an iterator for the vector as you said and hopefully I'm using it correctly in the for loop. I know you can get a vector's element by going "aVerse[i]" but how do you do that for a vector within a map? Verses[count].aVerse[count]????? :confused:
Also,
I'm assuming that if I have a function that loads the map, that when I leave the scope of the function, the map is gone too. Is that right? Or maybe since this is a global function it's still there? What's the best way to make a LoadMap() function that is accessable by many other functions? Should I have the LoadMap() function return a reference to the map?
If I want to have a function that loads the map and then displays the contents of the map that all other
functions can access (i.e. LoadVerses() and DeleteVerse()) does that mean that I have to make a class? :rolleyes: I've tried to learn classes a number of times and I it's just not getting through my head. I need to practice working with classes, accessing member variables and member functions of classes, inheritance, polymorphism, all that stuff.
Thanks again for all your help.