Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to append a char type variable to a string?

Tags:

c++

I want to append a char-variable containing the password to a string saying "Your password is: ". When I use the append function for this I get an error saying I can't use this function with string. (I can only use it with unsigned int and char.)

char pass[64];
std::cout << "Enter a password: "; fgets(pass, 64, stdin);    
std::string ssifre = "Your password is: "; ssifre.append(sizeof(pass), pass);

If you know another way to solve this, please comment. I don't need to use this function.

like image 692
Ferit Yiğit BALABAN Avatar asked Feb 28 '26 17:02

Ferit Yiğit BALABAN


1 Answers

This should work:

ssifre += pass;

It's using the += operator

(note that as @MichaelDoubez mentionned in the comments, ssifre.append(pass) would work, too.)

like image 59
Olivier Sohn Avatar answered Mar 02 '26 07:03

Olivier Sohn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!