Can't read String from User

I tried using gets(iname), std::getline(std::cin,iname) and std::cin.getline(iname,100,'\n'). But nothing seems to work. Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class store
{
	int ino, stock;
	char iname[100];
	float price;
	char chline;

	public:
	void NewItem()
	{
		cout<<"\n\nNew Item Registration:\n\nItem No.: "; cin>>ino;
		cout<<"\nItem Name: "; std::cin.getline(iname,100,'\n');
		cout<<"\nPrice: "; cin>>price;
		cout<<"\nQuantity: "; cin>>stock;
		cout<<"\nRegistered!";
	}
};


Suggestion Please!

I used the necessary header files.
I coded using Code Blocks 16.01 IDE and used minGW compiler...
Last edited on
Hi,
1
2
3
cout<<"\n\nNew Item Registration : \n\nItem No. : "; 
cin >> ino;
cin >> ws;


Tell your program to eat all remaining whitespace characters first before getline()...
Does that help you? :)
Oh Yes! That fixed it up. Thanks buddy!
Last edited on
Glad it helped :)
Topic archived. No new replies allowed.