我的C ++代码在代码块上出了什么问题?

时间:2017-01-24 18:26:55

标签: c++ codeblocks

#include <iostream>
#include <string>
using namespace;

int main()
{
    string word = " ";

    do
   {
        cout << "Enter a word that has at least 5 characters: " << endl;
        cin >> word;
       }while(word.size() < 5);

        char searchCh = '0';
       cout << "Enter a character and the program will tell " <<
        "you how many times it appears in the word " << word << "." << endl;
        cin >> searchCh;

        int counter = 0;

    for(int i = 0; i < (int)word.size(); i++ )
    {
        char ch = word.at(i)

        if(searchCh == ch)
        {
            counter++; //counter = counter + 1
        }
    }

    cout << "The number of " << searchCh << " 's in the word " << word <<  " is " << counter << ".\n";


}

我不断收到多个错误,例如: &#39; ENDL&#39;没有在范围内宣布 &#39; CIN&#39;在这方面没有申明 &#39;字&#39;在这方面没有申明         &#39;串&#39;在这方面没有申明         预期&#39;,&#39;或&#39;;&#39;之前&#39;}&#39;令牌

我正在使用代码块,如果有人可以回答它将非常感激。谢谢:D

1 个答案:

答案 0 :(得分:2)

你的第一行是

using namespace;

你可能想写

using namespace std;

但是,请阅读Why is using namespace std considered bad practice?