Hi!
I'm new to C++, been through the basics, and now I'm attempting to make a small console rpg-game where I want my stats (level, xp and such) to be saved in a file. I've successfully saved them into a txt-file, but how do I open it? I don't need to know how to type it onto the screen, but to put the data into variables. How?

EDIT: I want to load the stats in the beginning of the program so that they are there when you start it (saved from the last time).

Edited 7 Years Ago by DawnOfIkaros: n/a

read this

I've tried that, unfortunately it doesn't help me :(
Could you give me the code for loading the data from "test.txt" into the program, loading into the variables "str", "spd", and "acc". Sorry if my english isn't the best.

Its not hard.

#include<fstream>
using namespace std;

int main()
{
   ifstream readFromFile("test.txt");
   string var1, var2;
   readFromFile >> var1 >> var2 ;
  return 0;
}

Edited 7 Years Ago by firstPerson: n/a

Great, thanks, I'll try that :)
Does string define what the lines in the textfile are?

Worked great, without the strings aswell.
Problem was that I did it outside the main int ;) Thanks!

This question has already been answered. Start a new discussion instead.