Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1754301
  • 博文数量: 335
  • 博客积分: 4690
  • 博客等级: 上校
  • 技术积分: 4341
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-08 21:38
个人简介

无聊之人--除了技术,还是技术,你懂得

文章分类

全部博文(335)

文章存档

2016年(29)

2015年(18)

2014年(7)

2013年(86)

2012年(90)

2011年(105)

分类: C/C++

2011-04-20 22:00:42

  1. #include <iostream>

  2. using namespace std;
  3.   void string_replace(char *p,char src,char ch)

  4.   {

  5.       char *head=p;

  6.      while(*head!=0)
  7.       {

  8.          if(*head==src)
  9.             *head=ch;

  10.           ++head;
  11.      }

  12.  }
  13.     //static char *str="This is a test!";  also run
  14.   
  15.   int main()

  16.   {
  17.   char *str="This is a test!";

  18.       string_replace(str,' ','_'); cout<<str<<endl;
  19.         cin.get();

  20.       return 0;

  21.   }

这段代码,在http://kl.winu.cn/blog/index.php/author/kunlun/
上解释说有错误无法执行,但是在Qt 下面可以执行,不知道为什么,原则上字符串应该放在字符串池中,不再栈中,但是可以修改,和作者的解释有出入,求高人解释

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