blog.TangGaowei.com

VS2005 C++ 字符串相关处理

作者 传说一梦 写于 2008-05-08  | 294 次浏览 | 分类 » 软件开发 |

———————————————————————————-
分割字符串
———————————————————————————-
#include <string.h>
#include <stdio.h>

char data[] = "A string\tof ,,tokens\nand some  more tokens";
char seps[]   = " ,\t\n";   // 分隔符字符集
char *token;

void main( void )
{
   printf( "%s\n\nTokens:\n", data );
   /* Establish string and get the first token: */
   token = strtok( data, seps );
   while( token != NULL )
   {
      /* While there are tokens in "string" */
      printf( " %s\n", token );
      /* Get next token: */
      token = strtok( NULL, seps );
   }
}

———————————————————————————-
字符串转换成数字
———————————————————————————-

char* token = "20";   
int nHour;

nHour = atoi( token);

———————————————————————————-
数字转换成字符串
———————————————————————————-
_itoa( nHour,buf, 10);  // 10 代表十进制

char* token = "20";   
char* buf;
int r;
int nHour;
string sHour;
nHour = atoi( token);
nHour += 8;
_itoa( nHour,buf, 10);
sHour = buf;

[ 标签: 字符串 ]
[ 固定链接:http://blog.tanggaowei.com/2008/05/vs2005-c-4.html ]

相关日志

  • 暂无相关日志

发表评论


点击图片可以听验证码

订阅

 

手机访问

http://blog.tanggaowei.com/wap/

Google