Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,051 questions

40,769 answers

573 users

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

Learn & Practice SQL


85 views
asked Jul 11, 2019 by avibootz
retagged Jul 11, 2019 by avibootz

1 Answer

0 votes
#include <iostream>

using namespace std;

int main() {
    string s = "c c++ java php";
    
    char *p = new char[s.size() + 1];
    
    copy(s.begin(), s.end(), p);
    
    p[s.size()] = '\0'; 

    cout << p;
    
    delete[] p;

}



/*
run:

c c++ java php

*/

 





answered Jul 11, 2019 by avibootz

Related questions

1 answer 39 views
39 views asked May 27, 2023 by avibootz
1 answer 81 views
1 answer 127 views
5 answers 316 views
316 views asked May 10, 2021 by avibootz
3 answers 100 views
100 views asked May 9, 2021 by avibootz
...