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 133 views
2 answers 102 views
1 answer 154 views
154 views asked Feb 26, 2022 by avibootz
1 answer 92 views
1 answer 93 views
1 answer 145 views
...