Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

cross-platform woes

Options
  • 30-01-2003 9:20pm
    #1
    Closed Accounts Posts: 285 ✭✭


    The code below works on W2K with VC6 but will not work with Solaris 2.6 and g++ 3.1
    by not working I mean it compiles fine but I get a segmentation fault whenit runs. Its the "is>> field" thats causing the problem.
    Any ideas would be appreciated......

    #include <iostream>
    #include <fstream>
    #include <string>

    using namespace std;

    int main(int argc, char* argv[])
    {

    string field;
    ifstream is("test.txt", ios_base::in);

    if (is.fail())
    {
    cout << "\n Input file does not exist\n";
    return 0;
    }

    while(!is.eof())
    {
    is >> field;
    cout << field << endl;
    }

    is.close();
    return 1;
    }


Comments

  • Closed Accounts Posts: 285 ✭✭marauder


    update got it to work on RH8 with g++ 3.2 so it must be a g++ 3.1 peculiarity or maybe something on that machine


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    Have you tried wrapping it in a try block and seeing if anything is thrown?
    Might be worth calling is.exceptions(badbit | failbit) before you try that, so that badbit or failbit being set will raise an exception.


Advertisement