Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Help with Files and I/O Streams (http://www.go4expert.com/forums/help-files-i-o-streams-t23553/)

golf_girl32 12Oct2010 08:14

Help with Files and I/O Streams
 
I need help with this program. I know the file is opening but I'm not sure how to edit the numbers and stuff that is in the file. This is what I have so far.

Code:

#include <fstream>
#include <iostream>
#include <cstdlib>

int main()
{
    using namespace std;
    ifstream input;
    ofstream output;

    input.open("input.txt");
    if (input.fail())
    {
        cout<<"Input file opening failed.\n";
        exit(1);
    }

    output.open("grade.txt");
    if (output.fail())
    {
        cout<<"Output file opening failed.\n";
        exit(1);
    }

    input.close();
    output.close();

    return 0;
}


virxen 12Oct2010 19:55

Re: Help with Files and I/O Streams
 
send the txt file --->input.txt

xpi0t0s 13Oct2010 13:09

Re: Help with Files and I/O Streams
 
If you want to read data from input.txt into variable 'v' and write it out to grade.txt, use:
Code:

input >> v;
output << v;

For multiple variables just use the same as you would for cin/cout, i.e.:
Code:

input >> v1 >> v2 >> v3;
output << v1 << v2 << v3; // may need to add spaces ...<<v1<<" "<<v2...



All times are GMT +5.5. The time now is 05:24.