strcmp 遇上 string?
来源:互联网 发布:java输出hello world 编辑:程序博客网 时间:2024/06/05 04:42
string a = "bcd";
int e = strcmp(a,"bcd");
cout<<e<<endl;
编译使报错
【解决】int e = strcmp(a.c_str(),"bcd");
先说明一下,strcmp函数是对于C风格的char* 字符串的操作,而且需要头文件cstring.h
但是string类的话是C++风格的string函数库,需要头文件string.h,他里面已经帮助用户自己实现了函数符的重载,比如你的问题
int e = strcmp(a,"bcd");
对于a string类型操作char*的方法是不行的,你可以定义a为const,这样在函数内部实现的时候可以把string类型转化为char*的
0 0
- strcmp 遇上 string?
- string 遇上 “/0”
- string.h的strcmp的性能比较
- c string 用法,memcpy,strcpy,strcmp 等
- strcmp
- strcmp
- strcmp
- strcmp
- StrCmp
- strcmp
- strcmp
- strcmp
- strcmp
- strcmp
- strcmp
- strcmp
- strcmp
- strcmp
- 开始程序猿之路
- 树莓派学习笔记——交叉编译练习之SQLite3安装
- vs2013配置opencv2.4.9
- 6-1. 简单计算器(20)
- 以后就在这里写技术学习笔记啦
- strcmp 遇上 string?
- 使用Socket使用域名连接服务器
- kaggel[6] - recommend missing links in a social network
- Linux命令
- myeclipse10安装tomcat插件方法
- [Python]os模块和os.path模块的常用函数
- HDU 3188 Just A Triangle JAVA 实现
- 微软将裁员1.8万人
- HDU 2159 FATE(完全背包+二维费用背包)