I wrote a simple program to take input till the char array is filled up. But i seem to be getting a problem during runtime that the program takes input continuously and never stops.
Pls help in identifying the problem.(there were no errors during compiling)

#include<iostream>
#include<string>
using namespace std;
int main(){
char a[10];
int n=0;
while(cin>>a[n]) {n++;}
cout<<a;
return 0;
}

I would recommend reading the following thread for detailed explanation on why cin is better to be used in while loop.

http://www.parashift.com/c++-faq-lite/input-output.html
[15.2] Why does my program go into an infinite loop when someone enters an invalid input character?

another thing if you want to break on the size of array.. why don't you use. the for loop?

for (int i=0; i<10; ++i)
{
   cin >> c;
   a[i] = c;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.