There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell display driver drivers email error excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem ram router slow sound trojan usb video virus vista windows windows vista windows xp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
inputing into files


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
calculus87's Avatar
Member with 34 posts.
 
Join Date: Sep 2003
22-Sep-2003, 01:36 PM #1
inputing into files C++
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 : 22-Sep-2003 03:39 PM.
calculus87's Avatar
Member with 34 posts.
 
Join Date: Sep 2003
22-Sep-2003, 04:54 PM #2
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.
calculus87's Avatar
Member with 34 posts.
 
Join Date: Sep 2003
23-Sep-2003, 09:37 AM #3
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
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:15 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.