Cin Input.

Hi there,
I can't input my balance value. As I put full name for the account holder string with spaces, it takes the second word after the space as a balance value.


1
2
3
4
5
6
7
8
9
10
11
12
istream& operator >> (istream& in, BankAccount& k)
{
	string s;
	double b;
	cout << "Enter Account Holder's Name: ";
	in >> s;
	k.setAccountHolder(s);
	cout << "Enter the Balance: ";
	in >> b;
	k.setBalance(b);
	return in;
}
Last edited on
in >> s;
replace with
 
std::getline(in, s)
as the stream extraction operator >> skips white-space
Thanks gunnerfunner, is it possible if I dont want to use string lib? :)
You've already got string in your current program, OP line 3, why change it? I suppose you could use c-style strings (char arrays) if you really want to but that would be a step backwards
Topic archived. No new replies allowed.