#include <iostream>
#include <cstring> //which one should I use...out of these three header files
#include <string> //whats difference in each of them
#include <string.h>
int main()
{
std::string first_name;
std::string second_name;
std::cout << "\n First name : ";
std::cin >> first_name;
std::cout << "\n Second name : ";
std::cin >> second_name;
strcat(first_name," "); //not working
strcat(first_name,second_name); //not working
std::cout << first_name;
return 0;
}
I've done programs on c++ strcat (string catenation) earlier. I followed new tutorials and the new IDE compilers(which contains new data type viz. 'string' ). When I tried the same using this, then it is giving me errors.
ERROR:- ||=== Build: Debug in string1 (compiler: GNU GCC Compiler) ===| C:\Users\Admin\Desktop\c++ projects\string1\main.cpp||In function 'int main()':|
C:\Users\Admin\Desktop\c++ projects\string1\main.cpp|16|error: cannot convert 'std::string {aka std::basic_string}' to 'char*' for argument '1' to 'char* strcat(char*, const char*)'|
C:\Users\Admin\Desktop\c++ projects\string1\main.cpp|17|error: cannot convert 'std::string {aka std::basic_string}' to 'char*' for argument '1' to 'char* strcat(char*, const char*)'|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|