>> operator overloading error ambiguous

Hello,
This is my operator overloading :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
istream& operator>>(istream & in, vector<int> & final) {
	string a;
	int aa;
	int num;

	in>>a;
	
	for (int i=0; i<a.size(); i++) {
		aa=a[i];
		num=aa-47;
		final.push_back(num);
	}
	
	return in;
}


and in my main program :
1
2
3
4
5
6
7
8
ifstream fin("numbers.txt");
         if (!fin) {
		cout << "Not open";
                return 0;
    	}
	
	vector<int> a;
	fin>>a;


The file has numbers each on a separate line. I want to input each number into a vector of integers as one digit integers.

What am I missing ?

Cheers,
Last edited on
1
2
3
4
5
6
for (size_t i = 0; i != a.size(); ++i)
{
    char tmp[] = { a[i], 0 }; // a null terminated string of the char
    int num = atoi(tmp); // convert char to a number
    final.push_back(num);
}
Last edited on
Ok, thanks. Although I still get this error :

Ambiguous overload for 'operator>>' in 'fin>>a'

when I try fin>>a; in the main.


Cheers,
You must have something else in your program that can pass as a match.
Found the mistake. Some stupid typo...


Thanks,

Cheers
Topic archived. No new replies allowed.