0

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 by DawnOfIkaros: n/a

2
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by DawnOfIkaros
0

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.

0

Its not hard.

#include<fstream>
using namespace std;

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

Edited by firstPerson: n/a

0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.