#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
答案 0 :(得分:2)
你的第一行是
using namespace;
你可能想写
using namespace std;