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).

Recommended Answers

All 7 Replies

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;
}

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!

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

What do you mean?

What do you mean?

Nevermind :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.