Cin Input.

Apr 6, 2017 at 7:33am
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 Apr 6, 2017 at 7:40am
Apr 6, 2017 at 8:57am
in >> s;
replace with
 
std::getline(in, s)
as the stream extraction operator >> skips white-space
Apr 6, 2017 at 9:18am
Thanks gunnerfunner, is it possible if I dont want to use string lib? :)
Apr 6, 2017 at 9:31am
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.