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.
A little change to your code would do it.
Change strcat(e,c) to strncat(e, &c, 1)
But please, just use
std::string
:stncat()
concatenates two strings, method signature looks like this,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
If you are desperate to do it in the C style, use: