GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, March 8, 2011

CPP - Copy Of String

For copying some string, the function used is strcpy(dest, source)

#include <cstring>

using namespace std;
int main(){
    char source[] = "Indonesia is a nice one";
    char dest[100];    // you cannot use char *dest;
    strcpy(dest, source);
    cout << source << endl;
    cout << dest << endl;
    strcpy(dest, "Will also like this one");
    cout << dest << endl;
    return 0;
}
Share/Bookmark

No comments:

Post a Comment