I want to get one character from cin.get()
and add it to a array character. I use strcat but the single character has an error. please help me if you know. thanks for all answers.
void main (void)
{
char e[80]="hi";
char c;
cin.get(c);
strcat(e,c);
cout << "e: " << e << endl;
getch();
}
This is part of my code that I want to do this.
stncat()
concatenates two strings, method signature looks like this,
char * strncat ( char * destination, const char * source, size_t num );
but you are trying to concatenate a char which is not right!
As you are using C++, it is safe and easy to do it in C++ style rather than using C style.So use
std::string cAsStr(c); // Make the string
e += aAsStr; // + operator does the concatenation
If you are desperate to do it in the C style, use:
char cAsStr[] = { c, '\0' }; // Making a C-style string
strcat(e, cAsStr); // Concatenate
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments