Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1681337
  • 博文数量: 210
  • 博客积分: 10013
  • 博客等级: 上将
  • 技术积分: 2322
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-25 15:56
文章分类

全部博文(210)

文章存档

2011年(34)

2010年(121)

2009年(37)

2008年(18)

我的朋友

分类: C/C++

2010-06-23 20:44:20

#include "stdafx.h"
#include<iostream>
#include<string>
#include<cstring>

using namespace std;

char * strcpytemp(char *to,const char *from){
    if(to==NULL||from==NULL)
        throw "Invalid arguments";
    char *copy = to;
    while((*to++=*from++)!='\0')
        ;
    return copy;
}
int _tmain(int argc, _TCHAR* argv[])
{
    char *from = "hello";
    char *to=new char[strlen(from)+1];//在用strcpy之前一定要保证目标字符串有足够的内存,不然,嘿嘿,可以试试
    to=strcpytemp(to,from);
    cout<<to<<endl;
    cout<<strlen(to)<<endl;
    return 0;
}


阅读(476) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~