• Source
    1. /**
    2.  * String is same as char type array of C language.
    3.  * But there are several build in functions in String
    4.  * Thus, we can use it more fairly then char array.
    5.  * Remember, we can't take String input using scanf.
    6.  * Rather, we need to use "cin".
    7. */
    8. #include<stdio.h>
    9. #include<string.h>
    10. #include<string>
    11. #include<iostream>
    12. using namespace std;
    13.  
    14. int main()
    15. {
    16. char st[]="This not a good code";
    17. string str="Good line";
    18.  
    19. cout << str << " and -> " << st <<endl; // in printf str.c_str()
    20. puts("Give a line");
    21. cin >> str; // no other way to take input
    22.  
    23. cout << str << endl;
    24. printf(" The lenght is %d and first char %c\n", str.length () , str[0] );
    25. str.insert(0, st );
    26. cout << str << endl;
    27. str.erase();
    28. return 0;
    29. }