1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Opening files with a twist, C++

Discussion in 'Software Development' started by calculus87, Sep 26, 2003.

Thread Status:
Not open for further replies.
  1. calculus87

    calculus87 Thread Starter

    Sep 4, 2003

    Okay, in my program I open a file and begin to put data in the file. Now before I am finished putting the data in the file I need to use some of the data.

    okay for example
    data in file1:
    3 4

    Now for the next input I need to take the sum of the first two statements. So the next spot in the statement would be 7

    3 4 7

    afterwards I go on inputting data.

    3 4 7 1 ...

    I tried to do a function inside a function, where the outer function opens the file, and begins to input data into it.
    Then the inner function is called. It opens the file and takes the
    first two inputs, does the conversions, adds them, converts them back then inputs the string into the file then exits.
    The outer function then continues inputing into the file.

    When I run my code I am supposed to have a=3 and b =4 but they are blank.

    so my question is this.
    1) can it be done?
    2) here is some of the code that I have tried, any suggestions on how to fix this code?

    Thanks for the help
    int main()
    fstream scan;
    scan.open("calcout.txt", ios::eek:ut| ios::in);
    output<<"3 ";
    output<<"4 ";
    output<<"1 "
    return 0;
    string getstrings()
    string a, b;
    ifstream input2;
    double s1,s2,sum=0;
    string t1;
    stringstream stream;


    sum = s1 + s2;

    stream << sum;
    t1 = stream.str();
    return t1;
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/167580

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice