Hi
I just started learning programming language. In C++ i am facing problems with string i not understood string properly if anyone know about strings in C ++ please let me know
Thanks
Hi
I just started learning programming language. In C++ i am facing problems with string i not understood string properly if anyone know about strings in C ++ please let me know
Thanks
In C++ there are C-style strings and C++-style strings available. It indicates that the one-dimensional char, wchar_t, byte (or equivalent) array or the pointer to such an array must be treated as a string.
Example
Code:// cpp_attr_ref_string.cpp // compile with: /LD #include "unknwn.h" [module(name="ATLFIRELib")]; [export, string] typedef char a[21]; [dispinterface, restricted, uuid("00000000-0000-0000-0000-000000000001")] __interface IFireTabCtrl { [id(1)] HRESULT Method3([in, string] char *pC); };
c_str Syntax:
The function c_str() returns a const pointer to a regular C string, identical to the current string. The returned string is null-terminated.Code:#include <string> const char* c_str();
string is anything that contains more than one character strung together. Here is the Example.
Code:#include <iostream> #include <string> using namespace std; int main () { char *line = "short line for testing"; // with no arguments string a1; a1 = "Anatoliy"; cout << "a1 is: " << a1 << endl; // copy constructor string a2 (a1); cout << "a2 is: " << a2 << endl; // one argumen string a3 (line); cout << "a3 is: " << a3 << endl; // first argumen C string // second number of characters string a4 (line,10); cout << "a4 is: " << a4 << endl; // 1 - C++ string // 2 - start position // 3 - number of characters string a5 (a3,6,4); // copy word 'line' from a3 cout << "a5 is: " << a5 << endl; // 1 - number characters // 2 - character itself string a6 (15,'*'); cout << "a6 is: " << a6 << endl; // 1 - start iterator // 2 - end iterator string a7 (a3.begin(),a3.end()-5); cout << "a7 is: " << a7 << endl; // you can instantiate string with assignment string a8 = "Anatoliy"; cout << "a8 is: " << a8 << endl; return 0; }
Bookmarks