首页 > 编程 > C++ > 正文

c++语言中类型的转换

2019-11-06 06:40:05
字体:
来源:转载
供稿:网友
// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include "stdio.h"#include <string> #include <cstdlib>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ string str = "1234"; const char * a = str.c_str(); //将string 类型转换为const char * 类型 int i = atoi(a); //字符串const char *转换成int 型 i++; PRintf("the value of i is %d",i); getchar(); return 0;}可以看到,c++对类型比较严格,以后会遇到各种奇葩的转化,以后有时间会画一个转化图。

参考资料: 【1】<<剑指offer 案例1>> p245 【2】c++参考官网http://www.cplusplus.com/reference/string/


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选