What is use of c_str function In c++

前端 未结 7 1222
忘了有多久
忘了有多久 2020-12-04 06:30

I have just started reading C++ and found c++ having rich functions for string manipulation which C does not have. I am reading these function and came across c_str()<

相关标签:
7条回答
  • 2020-12-04 06:59

    Oh must add my own pick here, you will use this when you encode/decode some string obj you transfer between two programs.

    Lets say you use base64encode some array in python, and then you want to decode that into c++. Once you have the string you decode from base64decode in c++. In order to get it back to array of float, all you need to do here is

    float arr[1024];
    memcpy(arr, ur_string.c_str(), sizeof(float) * 1024);
    

    This is pretty common use I suppose.

    0 讨论(0)
提交回复
热议问题