Midnightuk wrote:I have a defined a char of size 6
How can i validate the input so if a user enters 7 or more characters then an invalid size is shown and it will not override os memory.
- Code: Select all
char product[6];
cout<<"enter product: ";
cin>>prod;
One way would be to use the std::string class, which overcomes many of the limitations of using character arrays for strings.
You can limit the input to your char array with:
cin >> setw(6) >> prod;
