将contst char*数组中的某些数据部分复制到另一个const char*数组中

Hum*_*Hum 0 c++ string visual-c++

我能够将一些数据从char数组复制到循环中的另一个char数组中.例如,我想提取并显示char数组的每2个字符b.但它不起作用const char *.任何人都可以建议我为什么不与之合作const char *.其实我需要这样做const char*.

char array[] = "HelloRamBilasj";

cout << "total length of array buffer:" << strlen(array) << endl << endl;
int totalGoLength= strlen(array)/2 ; //divide by number of elements you want to display in one loop

cout << "required length of alice buffer:" << totalGoLength << endl << endl;

int oneGoCount=1;
int start=0;//starting index to copy
int next=2;//end index to copy

while( oneGoCount <= totalGoLength) {

    char *b = new char[100];
    // now copy the elemet into b.
    std::copy(array+start, array+next, b);

    for (int i = 0; i < 2; ++i){
        cout<< "the value of b is"<<b[i]<<endl;

    }
    cout<<endl<<endl;

    delete [] b;//erase the contents of b.
    start=start+2;//increment the next index
    next=next+2;//increment the next index

    oneGoCount=oneGoCount+1;

}//end of while
Run Code Online (Sandbox Code Playgroud)

Bau*_*gen 7

您无法将数据更改为一个const char*点,因为它指向的数据是const.