Loading variables from file

Something seems wrong with this code, the save function is alright and it saves the variables as it should but it doesen´nt load.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
  void load(vector<Konto>&konton)
{ 
	cout << "Test";
	cout << konton.size() + 1 << endl;

	ifstream fin("Bank.txt");

	int nummer; (accountsnumber)
	string innehavare; (holder)
	double saldo; (debt)
	double rantesats; (interest)
	
	konton.clear(); // Clear the contents of konton (accounts)

	while(fin >> nummer >> innehavare >> saldo >> rantesats) 
	{
		konton.push_back(Konto(nummer, innehavare, saldo, rantesats));
	}

	cout << konton.size() << endl;

	BubbleSort(konton);
	cout << konton.size() << endl;
	for (unsigned int i = 0; i < konton.size(); i++)
	{
		cout << "Kontonummer: " << konton[i].Nummer() << endl;
		cout << "Innehavare: " << konton[i].Innehavare() << endl;
		cout << "Saldo: " << konton[i].Saldo() << endl;
		cout << "R\x84ntesats: " << konton[i].Rantesats() << endl << endl;
	}

	cout << "\n" << endl;
}
Maybe your file isn't opening: You should check the flags on fin after you construct it.
It seems like the file isn´t opening. What can I do about it?
Make sure that the file is located in the directory where you're running the program.
It is...hmmm....
Are you really sure it is? How are you running the program?
Now I got it. It depended on this string I tried to store.

1
2
innehavare = fornamn + " " + efternamn;
//holder = firstnamn + " " + lastname; 


Instead I created two strings:

1
2
string firstname;
string lastname;


and never combined them. I think the whitespace in + " " + maked the troble with fin. Now the function works as it should. Thanks all! / P
Last edited on
Topic archived. No new replies allowed.