String Vs Char *str

Dear i am very new in C++ and i am bit confuse also. i want to work on strings while searching about the functions of strings i found strcat strcopy strncat etc but every functions work with char *str not for strings for example when i wrtie

string str1;
string str2;
getline(cin,str1);
getline(cin,str2);
strcat(str1,str2);
cout<<str1;

not working compilation error

but if i declare
char *str1,*str2;
cin.getline(str1,256);
cin.getline(str2,256);
strcat(str1,str2);
cout<<str1;

this works. i don't want to use char *str as string i want to use string str;
what is the difference between them and what is the difference in codes? can anyone explain please
i am using dev-cpp compiler.
thanks in advance
Last edited on
> i want to use string str;

Yes; start learning programming in C++ with std::string and std::vector<>.


> what is the difference between them and what is the difference in codes?

Read this tutorial:
http://www.mochima.com/tutorials/strings.html


> not working compilation error

1
2
3
4
5
6
7
std::string str1;
std::string str2;
std::getline(cin,str1);
std::getline(cin,str2);
//strcat(str1,str2);
std::cout << str1 + str2 ;
str1 += str2 ; 
sorry i forgot to tell you that i already wrote using namespace std; at the top
i want to know the functions with strings
> i want to know the functions with strings

http://en.cppreference.com/w/cpp/string/basic_string
Last edited on
Topic archived. No new replies allowed.