How to convert a std::string to char* in C++

1 Answer

0 votes
#include <iostream>
#include <string>

int main() {
    std::string str = "c++";
    
    char* p = str.data();
    
    std::cout << p << std::endl;
}



/*
run:

c++

*/

 



answered Jul 15, 2024 by avibootz

Related questions

1 answer 145 views
2 answers 116 views
1 answer 160 views
160 views asked Feb 26, 2022 by avibootz
1 answer 102 views
1 answer 106 views
1 answer 168 views
...