C++ command line help

newbiepcuser

Diamond Member
Jan 1, 2001
4,474
0
0
If anybody can help me, I would appreaciate it.

command line C++

I have character array of 5, and I want to either allow a user to input as many character and discard anything after five bytes, append the 5 with \0 or stop the user the from input more than 4 characters.

ie

char temp [5];

cout <<"please input your your information : "<<"\n";

//user types garble, but i only want 4 characters and null appended;


std:fstream.write(temp,4);


 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
Put a loop to read each character instead of a string

while (true)
{
icount++
if (icount > 4)
// reject anything entered after the fourth character
else
// accept characers 1-4
...
}