注册 登录
编程论坛 VC++/MFC

问个很菜的问题

落落清欢v 发布于 2011-07-30 23:19, 795 次点击
#include<iostream>
#include<string>
using namespace std;
int main(){
    string line;
    string a("1");
    string S;
    while(getline(cin,line)){
        if(这里我想填个判断line不等于空值的条件){
            S=line+a;
            cout<<S<<endl;
        }else
            cout<<"请输入有效字符"<<endl;
        }
        return 0;
        }
if后面那个条件该怎么写。C++中没有null这个关键字,让我很迷茫,初学者,求指教。
5 回复
#2
fgfdfg2011-07-30 23:22
if(line != 0)
#3
落落清欢v2011-07-30 23:25
试过了,错误信息如下
1>i:\code\c&c++\测试\测试\运算符.cpp(9): error C2678: 二进制“!=”: 没有找到接受“std::string”类型的左操作数的运算符(或没有可接受的转换)
1>          d:\program files (x86)\vs2010\vc\include\system_error(425): 可能是“bool std::operator !=(const std::error_code &,const std::error_condition &)”
1>          d:\program files (x86)\vs2010\vc\include\system_error(432): 或       “bool std::operator !=(const std::error_condition &,const std::error_code &)”
1>          尝试匹配参数列表“(std::string, int)”时
#4
落落清欢v2011-07-30 23:29
if(line.size()!=0)
从其他地方找到了。。
嘿嘿嘿。
#5
wdm16024342011-07-31 10:42
if(line !=‘\0’)
#6
落落清欢v2011-07-31 23:59
以下是引用wdm1602434在2011-7-31 10:42:59的发言:

if(line !=‘\0’)

刚试了下,可以。。
但现在纠结空格,输空格条件判断依旧成立= =!
看来我得换其他思路了。
1