why f gives a empty string can anyone explain
string tmp= “abc”;
cout << f;
Use f+=tmp which means f = f+tmp instead
what is wrong in
this means f is assigned a string which contains first char in tmp.
is giving empty string
If it is only for assigning f to the first char then consider using f=tmp; instead
f=""+tmp; what is wrong in this I just cast a char to string using “”
The problem is you cannot directly add char (i.e temp) to a string like that you will get a warning but your code will run.
adding ‘std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator>::value_type’ (aka ‘char’) to a string does not append to the string [-Wstring-plus-int]
Assign “” to a string variable and things should work just fine.