Results 1 to 4 of 4

Thread: Problems with String in C++

  1. #1
    Join Date
    Jun 2009
    Posts
    6

    Problems with String in C++

    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

  2. #2
    Join Date
    Oct 2008
    Posts
    89

    Re: Problems with String in C++

    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);
    };

  3. #3
    Join Date
    Aug 2008
    Posts
    68

    Re: Problems with String in C++

    c_str Syntax:
    Code:
    #include <string>
        const char* c_str();
    The function c_str() returns a const pointer to a regular C string, identical to the current string. The returned string is null-terminated.

  4. #4
    Join Date
    Nov 2008
    Posts
    29

    Re: Problems with String in C++

    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;
    }

Similar Threads

  1. Erase end of a string
    By New ID in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 05:57 AM
  2. String manipulation in c
    By BoanHed in forum Software Development
    Replies: 3
    Last Post: 02-12-2009, 01:07 PM
  3. How to Manipulate String using PHP String Functions
    By ComPaCt in forum Software Development
    Replies: 3
    Last Post: 21-09-2009, 09:07 AM
  4. String concatenation in VB6
    By Harshini in forum Software Development
    Replies: 2
    Last Post: 21-03-2009, 09:25 PM
  5. Replies: 4
    Last Post: 28-06-2008, 01:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,750,361,994.38147 seconds with 16 queries