返回信息流写程序遇到:
for(vector<string>::iterator iter=expression.begin();iter<expression.end();iter++)
const char*a=(*iter).c_str();
if(a!="+"&&a!="-"&&a!="*"&&a!="/")//即使a为"+",if语句还是成立
{
double temp=atof((*iter).c_str());
res.push(temp);
}
在网上了解到iter的类型和常规字符串"abcd"等不同,望祥解。
这是一条镜像帖。来源:北邮人论坛 / cpp / #36228同步于 2010/3/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
iterator指示的string和C字符串比较
jiangnanbuyi
2010/3/2镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
呃,上面程序有问题(string 才能用!=),但是即使是if(!strcmp(a,"+"));或者string a=*iter;if(a!="+"),还是不对。
【 在 jiangnanbuyi 的大作中提到: 】
: 写程序遇到:
: for(vector<string>::iterator iter=expression.begin();iter<expression.end();iter++)
: const char*a=(*iter).c_str();
: ...................
就是啊, char*类型怎么能用 == 和 != 比较相等呢
【 在 wks 的大作中提到: 】
: try:
: #include <cstring>
: using namespace std;
: ...................
LZ在写计算器吧~
用string把
string s(*iter);
s != "+"