[英]What is wrong with my C++ code on 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";
}
I continuously receive multiple errors such as: 'endl' was not declared in the scope 'cin' was not declared in this scope 'word' was not declared in this scope 'string' was not declared in this scope expected ',' or ';'我不断收到多个错误,例如:'endl' 未在此范围内声明 'cin' 未在此范围内声明 'word' 未在此范围内声明 'string' 未在此范围内声明 ',' 或 ' ;' before '}' token
在 '}' 标记之前
I am using codeblocks, if anyone could answer it would be much appreciated.我正在使用代码块,如果有人能回答,将不胜感激。 Thank you:D
谢谢:D
One of your first lines is你的第一行是
using namespace;
You probably wanted to write你可能想写
using namespace std;
However, please read Why is using namespace std considered bad practice?但是,请阅读为什么使用命名空间 std 被认为是不好的做法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.