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 130 views
1 answer 194 views
1 answer 182 views
182 views asked May 8, 2021 by avibootz
2 answers 214 views
1 answer 138 views
1 answer 139 views
...