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

File I/O in C++

Options
  • 27-01-2009 3:41pm
    #1
    Users Awaiting Email Confirmation Posts: 351 ✭✭


    Before anyone asks, yes I have tried google :) I'm just looking for a good tutorial on reading in values from a simple text file. I've found some code to do this using fstream library however the data is read in as strings and there is no native convertor from strings to integer values. If anyone can point me to code that might do that I'd greatly appreciate it. It's been a while since I last coded in c++.

    Many thanks in advance
    RD


Comments

  • Closed Accounts Posts: 225 ✭✭marktsang


    you need to write to a stringStream

    int val;
    string myString = "100";
    std::stringstream (myString) >> val;


    mark


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    sorted it out guys - thanks for the help - used the ifstream to stream the data straight to an integer (rather than using the stringstream).


Advertisement