There is no standard and quick way to do this. I can come up with some options.
Let's pretend that:
char *text = new char[20];
cin >> text;
Note. We needknow that the capacity is 20! I would recommend that you use some constant for this, especially if it will be used for other lines as well.
Ok, first option - use std::stringstream
std::stringstream ss;
ss << setw( 20 - 1 ) << setfill( '-' ) << text;
// ^^^^ we need one byte for the '\0' char at the end
ss >> text;
But it is rather slow.
Fill in the characters manually:
int length = strlen( text );
for( int i = length; i < 20 - 1; ++i )
{
text[ i ] = '-';
}
text[ 20 - 1 ] = '\0';
, , char* ( ++) std::string.
std::string sText;
std::cin >> sText;
sText.resize( 20, '-' );
Voilà! (:
, delete[] text; ( , - delete[]), 100% . , .. ?!:))
, 19 20-1, "" -1, .