If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > inputing into files

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-22-03, 13:35
calculus87 calculus87 is offline
Registered User
 
Join Date: Sep 2003
Posts: 23
files

Hello,
okay here is what I am trying to do.
in my program I open up a file and use the while(getline(input,word))
loop go through the text file. After I have gone through the entire file I close it. Now, I would like to go through the file again in the same function, but when I attempt to use the loop again, I am not able to. Now I am not sure why, I am guessing the reason is because I am now at the end of the file, but I am not certain.

I know there is a command that says that I open a file and start at the end. Is there possible a command that makes me start at the beginning?

std::ios::ate

std::ios::???


Thanks,
Ronald
__________________
This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.

Last edited by calculus87; 09-22-03 at 15:52.
Reply With Quote
  #2 (permalink)  
Old 09-22-03, 16:54
calculus87 calculus87 is offline
Registered User
 
Join Date: Sep 2003
Posts: 23
some code

Here is some example code.
The file contains
Cat
Dog

that is it. Now when I execute it. It will print out:
Cat
Dog

and that is it. It should print go:
Cat
Dog
Cat
Dog

any thoughts?

#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;
#include <string>
#include "time.h"
#include <vector>
#include <algorithm>
#include <sstream>

int main()
{
string calcstring;
ifstream input1;
input1.open("calc.txt",ios:ut);
while (getline(input1,calcstring))
cout<<calcstring<<endl;
input1.close();
input1.open("calc.txt",ios:ut);
while (getline(input1,calcstring))
cout<<calcstring<<endl;
input1.close();


return 0;
}


Thanks for the help
Sincerely,
Ronald
__________________
This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
Reply With Quote
  #3 (permalink)  
Old 09-23-03, 09:36
calculus87 calculus87 is offline
Registered User
 
Join Date: Sep 2003
Posts: 23
I found it. You call this right after the first time you do input.close();

input1.clear(); // Call clear() to clear the fail() flag before reopening
__________________
This message is a natural product made from recycled electrons. The slight
variations in spelling and grammar enhance its individual character and
beauty and in no way are to be considered flaws or defects.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On