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

1 Answer

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

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



/*
run:

c++

*/

 



answered Jul 15, 2024 by avibootz

Related questions

1 answer 71 views
1 answer 131 views
1 answer 121 views
121 views asked May 8, 2021 by avibootz
2 answers 114 views
...