Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Question about c++ file i/o

  1. Mar 8, 2008 #1
    i have a txt file full of numbers and i just want to take the first 5 digits, save it has one number, shift over 1 digit, take another 5 digits, save it, and so on until the end of the file

    here is the code
    Code (Text):

        fstream Prime;
        if (!Prime.is_open()) { cout << "unable to open"; }
        else if (Prime.is_open()) {
            cout << "File opened successfully\n";
            cout << str2 << endl;
            cout << str2;
    right now i'm just trying to print the first 5 digits and then the next 5 digits but the second number won't print. what am i doing wrong?

    I tried using the get function but using atoi kept giving errors.
  2. jcsd
  3. Mar 9, 2008 #2
    You are going right, so now, check the error flags in Prime.

    cout << str2 << endl;
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook