Subscript operatörünü kullanabilirsin msg[0], yapmak istediğin C stili bir diziye aktarmak ise zaten string bunun için bir fonksiyon sağlıyor msg.c_str(); Başka bir diziye kopyalamak için strcpy kullanabilirsin vs.
/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main() {
string msg = "test message";
for(auto chr: msg) {
cout << chr << endl;
}
char arr[25];
std::strcpy(arr, msg.c_str());
cout << "arr: " << arr << endl;
for(int i=0; i< msg.size(); ++i) {
cout << msg[i] << endl;
}
return 0;
}
Bu sitenin çalışmasını sağlamak için gerekli çerezleri ve deneyiminizi iyileştirmek için isteğe bağlı çerezleri kullanıyoruz.