c++语言中类型的转换

来源:互联网 发布:华为 海思 媒体算法 编辑:程序博客网 时间:2024/06/10 11:15
// 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/

0 0
原创粉丝点击