How to convert part of a string to char array in C++

1 Answer

0 votes
#include <iostream>
  
using namespace std;
  
int main() {
    string s = "c c++ java php"; 
    char arr[8]; 
    
    strncpy(arr, s.c_str(), 8);
      
    for (int i = 0; i < sizeof(arr); i++) { 
        cout << arr[i] << endl;
    } 
}
 
 
/*
run:
 
c
 
c
+
+
 
j
a
 
*/

 



answered Aug 10, 2019 by avibootz

Related questions

1 answer 248 views
2 answers 269 views
1 answer 218 views
218 views asked Oct 5, 2016 by avibootz
1 answer 219 views
1 answer 182 views
...