VS2005 C++ 字符串相关处理
作者 传说一梦 写于 2008-05-08 | 350 次浏览———————————————————————————-
分割字符串
———————————————————————————-
#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 ]
| 分类 » 

