Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

File I/O in C++

  • 27-01-2009 03: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