GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Sep-2003, 14:36
calculus87's Avatar
calculus87 calculus87 is offline
Junior Member
 
Join Date: Sep 2003
Location: FLorida
Posts: 41
calculus87 is on a distinguished road

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.
  #2  
Old 22-Sep-2003, 15:56
calculus87's Avatar
calculus87 calculus87 is offline
Junior Member
 
Join Date: Sep 2003
Location: FLorida
Posts: 41
calculus87 is on a distinguished road

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?
CPP / C++ / C Code:
#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::out);
while (getline(input1,calcstring))
	cout<<calcstring<<endl;
input1.close();
input1.open("calc.txt",ios::out);
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.
  #3  
Old 23-Sep-2003, 05:57
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
Hey,

I think I effectively answered that question in a newer post, but just to be thorough...

When you open a file without any arguments, the pointer will go to the start of the file by default. Using the ios::ate argument, it will go to the end of the file, or ios::app to append to the file.

I can't see anything wrong with your code. I've tried it using gcc, it works grand!

GF
  #4  
Old 23-Sep-2003, 08:57
calculus87's Avatar
calculus87 calculus87 is offline
Junior Member
 
Join Date: Sep 2003
Location: FLorida
Posts: 41
calculus87 is on a distinguished road
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.
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
gxx linker accepts only 7 object files danielxs66 C++ Forum 1 12-Dec-2003 10:27
How to create batch files without DOS box? rhino1616 Web Design Forum 3 18-Aug-2003 11:00
any one knows about the address of the deleted files in FAT shaam C++ Forum 1 09-Aug-2003 17:18
Dedicated to JDS who does not like flash files jrobbio Open Discussion Forum 9 15-Feb-2003 04:24
publishing Drirector/Shockwave files ...? darrin Web Design Forum 1 04-Oct-2002 18:21

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:20.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.