// Jaime Muscatelli
// AOL SN: Jaime141974
Now, I have just switched from vb, and I know how stressful it is to get a grasp on strings using the char identifier. Even if you didn't, you still want to know how to manipulate strings easily right?
STRCMP // Used to compare strings
Lets say we made a simple password program, and we obviously needed to compare the real password against the password that the user entered. We would do this using an int variable, the strcmp method, and an if statement.
#define sRealPassword "JAIME" // The real password
int icompare; // The actual result
cout << "What is your name? : ";
cin >> sInput;
icompare = strcmp(sInput, sRealPassword);
if (icompare == 0) // if the strings match
cout << "Welcome\n";
That is it. All we did was compare the strings, and then took the result, and if it was equal, then do what we want.
STRCAT // To add strings together
This is what most of us want. This is how, in vb , you would say sString = "Jaime " + "Muscatelli".
I just used this today, after wanting to find how to do this for 2 months! I finally figured it out, and now I want to help others with the same dilemma. I used for my "Windows Enumeration" example here on PSC, where when a user double clicks on a list item, it will ask them "Do you wish to close 'Window name here'". 99% of programs use this string combination. For example, when you exit Microsoft Word, doesn't it ask you to save and then the file name.
This is just the usage, not a complete program...
strcpy(sMessage,"Are you sure you wish to close ");
Now, what we did here was assign the "Are you sure..." text into the sMessage variable (used strcpy), and then used strcat to add the data from sFileName to the sMessage variable. In other words, in vb this would look like:
sMessage = sMessage + sFileName.
Very simple right? Ok, we learned how to compare strings, assign data to them, and also add data to an already exisiting string. That is it! That was pretty simple. I am sorry for any grammatical errors. I know this is a lot more complex, yet I wanted to simplify it. There are more functions, yet these are crucial to c/c++.
Email Me with questions or comments. ALso, don't forget to check out my other submissions, and please leave comments and VOTE!!!!!