Problems with reading and wirting files!

Hi. Im learning about how to read and write to files. Im basically just copying what this guy does: http://thenewboston.org/watch.php?cat=16&number=67.
I already have the players.txt file in the same folder as my main.cpp file. (In the previous tutorial i was supposed to wirte this information using somewhat the same methods, but i had the same problem i am having now, so i just made the players.txt file myself) This is how it looks:
1 George 100
2 Michael 240
3 Sarah 1234

My problem seems to be that i can't use this: "while(theFile >> id >> name >> money)"

These are the errors i got:

1 IntelliSense: no operator ">>" matches these operands
operand types are: std::basic_istream<char, std::char_traits<char>> >> std::string c:\Users\Jan Helge\Documents\Visual Studio 2012\Projects\thenewboston67\thenewboston67\main.cpp 13 22 thenewboston67
2 IntelliSense: no operator "<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char>> << std::string c:\Users\Jan Helge\Documents\Visual Studio 2012\Projects\thenewboston67\thenewboston67\main.cpp 14 21 thenewboston67

And im using VS 2012 express. Any help will be greatly appriciated :D
This is my code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <fstream>
using namespace std;

int main() {
	
	ifstream theFile("players.txt");

	int id;
	string name;
	double money;

	while(theFile >> id >> name >> money) {
		cout << id <<", " << name << ", " << money << endl;
	}
	char r;
	cin>>r;
}
try #include <string>
Last edited on
hehe:) thanks
Topic archived. No new replies allowed.