c++ string求助
我想自己保存一个与源字符串无关的字符串,应该怎么实现?
#include <string>#include <iostream>void main(){ char* charTmp = new char[100]; charTmp = "hello world"; printf("%d\n",charTmp); printf("%s\n",charTmp); char* str1 = new char[100]; strcpy(str1,charTmp); delete []charTmp; printf("%d\n",str1); printf("%s\n",str1); delete []str1; system("pause");}#include <stdio.h>#include <string.h>int main(int argc, char* argv[]){ char* charTmp = new char[100]; //charTmp = "hello world"; strcpy(charTmp, "hello world"); printf("%d\n",charTmp); printf("%s\n",charTmp); char* str1 = new char[100]; strcpy(str1,charTmp); delete charTmp; printf("%d\n",str1); printf("%s\n",str1); delete str1; system("pause"); return 0;}
[解决办法]