whats the difference between C strings and C++ strings?

前端 未结 3 904
执笔经年
执笔经年 2020-12-24 14:31

whats the difference between C Strings and C++ strings. Specially while doing dynamic memory allocation

3条回答
  •  离开以前
    2020-12-24 15:08

    C++ strings are much safer,easier,and they support different string manipulation functions like append,find,copy,concatenation etc.

    one interesting difference between c string and c++ string is illustrated through following example

    #include                             
    using namespace std;
    
    int main() {
        char a[6]; //c string
        a[5]='y';
        a[3]='o';
        a[2]='b';
        cout<

    output »¿boRy¤£f·Pi»¿

    #include  
    using namespace std; 
    int main() 
    { 
      string a; //c++ string
      a.resize(6);
      a[5]='y';
      a[3]='o';
      a[2]='b';
      cout<

    output boy

    I hope you got the point!!

提交回复
热议问题