字符串的相关处理问题
2011-08-19 12:59
246 查看
itoa函数
原型:char *itoa( int value, char *string,int radix) ,其中的字符指针的参数既可以是数组名字(自动转化为指向数组的指针),也可以是动态申请的内存的指针。代码如下:
使用声明的字符数组:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char p[10] = {0}; //数组声明的时候全部初始化为0即'\0'
itoa(i, p, 10);
cout<<p<<endl;
return 0;
}
动态申请字符数组:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char *p = new char[10];
itoa(i, p, 10);
cout<<p<<endl;
return 0;
}
空字符的问题
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char p [10];
itoa(i, p, 10);
p[9] = '\0';
cout<<p<<p[9]<<"dd"; //怎么跟空格一个效果,空格和空字符什么关系
cout<<p[9]<<endl;
return 0;
}
空字符和空格字符的比较:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char p [10];
itoa(i, p, 10);
p[9] = '\0';
cout<<p<<p[9]<<"dd";
if (' ' == 0) //空格字符
{
cout<<"aaaa"<<endl; //此处无输出
}
else if ('\0' == 0)
{
cout<<"dddd"<<endl; //此处有输出
}
return 0;
}
格式化输出到字符数组:
sprintf
sprint_s
待完善
原型:char *itoa( int value, char *string,int radix) ,其中的字符指针的参数既可以是数组名字(自动转化为指向数组的指针),也可以是动态申请的内存的指针。代码如下:
使用声明的字符数组:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char p[10] = {0}; //数组声明的时候全部初始化为0即'\0'
itoa(i, p, 10);
cout<<p<<endl;
return 0;
}
动态申请字符数组:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char *p = new char[10];
itoa(i, p, 10);
cout<<p<<endl;
return 0;
}
空字符的问题
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char p [10];
itoa(i, p, 10);
p[9] = '\0';
cout<<p<<p[9]<<"dd"; //怎么跟空格一个效果,空格和空字符什么关系
cout<<p[9]<<endl;
return 0;
}
空字符和空格字符的比较:
#include "stdafx.h"
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i = 12;
char p [10];
itoa(i, p, 10);
p[9] = '\0';
cout<<p<<p[9]<<"dd";
if (' ' == 0) //空格字符
{
cout<<"aaaa"<<endl; //此处无输出
}
else if ('\0' == 0)
{
cout<<"dddd"<<endl; //此处有输出
}
return 0;
}
格式化输出到字符数组:
sprintf
sprint_s
待完善
相关文章推荐
- VC++中字符串编码处理的一些相关问题
- python 处理中文字符串的相关问题
- MFC 窗体按钮的按键的实现和字符串的相关处理函数的问题
- IOS开发笔记-字符串转换为日期时间存在时差问题的处理
- js处理字符串高亮相关内容,高光
- SpringMVC3.2 处理Ajax请求时返回json字符串的中文乱码问题
- hadoop0.20.2下相关问题处理方法
- ios图片处理相关问题
- Roman Order&&字符串处理问题
- 字符串处理相关
- 仙人掌相关问题的处理方法(未完待续)
- 关于字符串类型相关的问题总结
- 字段里字符串的处理问题
- VMWare安装苹果系统及相关问题处理
- 字符串数组初始化相关问题总结
- php处理敏感词时遇到的相关编码问题
- C++用纯字符串来处理高精度问题代码
- java字符串处理常见问题(不断补充)
- 转载一篇文章,这几天有相关问题要处理,学习一下先
- string类、字符串数组相关问题