Okay, I was making sure all of my beginner concepts were polished, (and so you will be seeing stupid beginner questions quite often), so I was playing around with C type strings (apparently C++ has a different string class).
Before posting here I read all them from the search bar above. What I don't seem to understand is the syntax for strcat and strncat...(They are almost similar)
Why does the pointer version in line 14 works sometimes, and what does it exactly mean?
Also, why does the line 15 version (it is for strncat, yes, but the strcat one works the same way)
I commented out the other ones since I (think) I understand them, but if you have something to offer, it would be most appreciated.
Also, what is up with strcoll? How is it different from strcmp?
{If you have any other sugggestions on what kind of strings I should be using in the future, then please tell. }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include<iostream>
#include<limits>
#include<string.h>
using namespace std;
int main()
{
char name1[]="First";
char name2[]=" Second";
char name3[]=" Fourth";
char name4[]=" Fourth";
//strcat
char* strcat(char* name1, char* name2);
strncat(name3,name4,4);
cout<<name1<<endl;
cout<<name3;
/*strcpy
strcpy(name1,name2);
cout<<name1;
//strcmp
int i = strcmp(name3,name4);
cout<<"\t"<<i;
//strlen
cout<<"\t"<<strlen(name1);
*/
std::cout << "Press ENTER to continue...";
std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
return 0;
}
|