Help
-
:confused:Hi i'm having difficulties, kinda fresh in C++ and I want to know how to do this code in C++: "Dim name As String" anyone tell me how to do it in C++ please
The answer is: it depends. In simplest 'C' terms (which also works for C++), strings are arrays of characters:
char str[128];
strcpy(str,"This is a string");defines a string
str
. Strings are terminated by a 0 byte, which marks the end of the string. In order to set the string, or assign one string to another, you have to call a function likestrcpy
. If you are using Microsoft Visual C++ and the MFC (Microsoft Foundation Class) library, you've got a class calledCString
:CString str;
str = "This is a string";CString
makes using strings a lot easier than the 'array of characters' approach. Instead of having to call functions to do simple operations like assigning one string to another, you can use a simple assignment:CString str1("This is string 1");
CString str2("This is string 2");
str1 = str2;CString also defines the '+' operator for doing string concatenation, along with others. The Standard Template Library (STL) defines a
string
class as well. I'm not familiar with the STL, but you should be able to find examples.
Software Zen:
delete this;
-
:confused:Hi i'm having difficulties, kinda fresh in C++ and I want to know how to do this code in C++: "Dim name As String" anyone tell me how to do it in C++ please
Read tutorials.... Don't try it, just do it! ;-)