Input/Output Streams

MMHMM I'm fairly new at this but I just need a little guidance with a program code.

What I did in this code was inputing and outputing data files. Which I then made it output to a file I called data.txt. Then used cout to print the data in the vector named orginal

But now I need to close the ostream and then open it with ifstream. for a text file I created (which I called data.txt using ofstream and then put that data into a new vector which I will call processed

Bascially I'm not sure how to do this? Do I need to create another function to make it close or can I use something to do it? Thanks for the help

/////////////////////////////////////////////My code

# include "std_lib_facilities.h"
struct Point
{
int xx, yy;
Point(int x,int y):xx(x), yy(y){ }

};

int main()
{


cout<<"Please enter input file name:";
string name;
cin>>name;
ifstream ist(name.c_str());
if(!ist)error("Can't Open input file",name);



cout<<"Please enter name of outpout file: ";
cin>>name;
ofstream ost(name.c_str());
if(!ost)error("can't open output file", name);



vector<Point>processed;




vector<Point>original;



cout<<"Please enter seven (x,y) pairs.\n ";
int x,y;
int a,b;


while (cin>>x>>y)
{
original.push_back(Point(x,y));
}

for(int i=0; i<original.size(); ++i)
ost<<'('<<original[i].xx<<','
<<original[i].yy<<")\n";





cout<<"Hopefully "<<original.size()<<" is the data.";

}
//////////////////////////////////////////////////////////

The member function ".close()" is the one that will close the ofstream object.
Is this the correct way on how to use it?
////
cout<<"Please enter name of outpout file: ";
cin>>name;
ofstream ost(name.c_str());
if(!ost)error("can't open output file", name);
name.close();
////
When I did the compiler gave me "error: 'struct String' has no member named 'close' "
does this mean I have to define it first?
In that case you want to close the ofstream object so the code you want is: ost.close();

cout<<"Please enter name of outpout file: ";
cin>>name;
ofstream ost(name.c_str());
if(!ost)error("can't open output file", name);
ost.close();



produced 7 9 11 9 7 and totally skipped the cout for the input
So how do I use use ifstream to open my .txt file [I need to close the ofstream and the open an ifstream for data.txt (which I had already made before)]
do i just use ost.open(); ?
Topic archived. No new replies allowed.