开发者社区> 问答> 正文

关于c++里vector的问题

using namespace std;
using std::vector;
int main()
{
vector words;
string input;
while (getline(cin,input)){
words.push_back(input);
for (decltype(words.size()) n = 0; n != words.size(); n++){
auto temp = words[n];
if (isalpha(words[n]))

}

}
system("pause");
}
程序没写完,words[n]下面有红线,说string类型不能转换为int,我想问这个words[n]到底是什么类型啊,鼠标放在auto temp显示的类型是char,为什么下面的words[n]变成string了
而且把auto temp和if这两行去掉换成直接输出cout<跪求大神解答~~!

展开
收起
a123456678 2016-03-05 11:56:52 2119 0
1 条回答
写回答
取消 提交回答
  • 你的代码有些问题:
    第一:getline()没有停止的条件,反正我在linux下尝试你的代码,必须CTRL+D才能停止!
    第二:你使用isalpha()函数,却给了个string类作为参数,它需要的是char啦!

    #include <vector>
    using namespace std;
    int main(void)
    {
        vector<string> words;
        string input;
        while(getline(cin,input)){
            if(!strcmp(input.c_str(),"END"))
                break;
            words.push_back(input);
        }   
            //for(decltype(words.size())n=0;n!=words.size();++n){
            for(int n=0;n!=words.size();++n){
                string temp=words[n];
                //if(is string type)---->>assume what you want ...
                if(isalpha('A')){//The argument is char Type No string
                cout<<"I Got alpha"<<endl;
                break;
                }   
            }   
        //system("pause");//use for win OS
        return 0;
    }
    2019-07-17 18:53:09
    赞同 展开评论 打赏
问答分类:
C++
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载