如题所述
ç¨coutç¼åc++æ¶æ¥åºå½æ°æ²¡æ声æçé误æ¯å 为没æincludeå°æè¦å¼ç¨çåºã
coutæå¨çåºæ¯iostreamï¼æ以è¦includeè¿æ¥ï¼å ¶ä»åºä¹ç±»ä¼¼ã
举ä¾ï¼
#include <locale>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string Test;
int count = 0;
cout << "String ?: ";
cin >> Test;
cin.get();
for(int i = 0; i < Test.length(); i++)
{
char c = Test[i];
if(isupper(c) == true)
{
count += 1;
}
}
coutæå¨çåºæ¯iostreamï¼æ以è¦includeè¿æ¥ï¼å ¶ä»åºä¹ç±»ä¼¼ã
举ä¾ï¼
#include <locale>
#include <iostream>
#include <string>
using namespace std;
int main()
{
string Test;
int count = 0;
cout << "String ?: ";
cin >> Test;
cin.get();
for(int i = 0; i < Test.length(); i++)
{
char c = Test[i];
if(isupper(c) == true)
{
count += 1;
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答 2018-03-13
cout 如果你前面没有声明命名空间的话 不能直接使用。可以std::cout 或者直接在全局声明
using namespace std;
using namespace std;
第2个回答 推荐于2017-09-19
一定要加上头文件和标准命名空间才能使用cout
#include <iostream>
using namespace std ;
这样才可以有直接使用cout
cout << "hello" ;
若只有头文件,没有命名空间,则使用前要加前缀
#include <iostream>
std::cout << "hello" ;追问
#include <iostream>
using namespace std ;
这样才可以有直接使用cout
cout << "hello" ;
若只有头文件,没有命名空间,则使用前要加前缀
#include <iostream>
std::cout << "hello" ;追问
加了的。
追答提供代码
本回答被提问者采纳第3个回答 2018-03-13
新版C++ 的cout 需要写成 std::cout。
或者在main函数前声明命名空间
using namespace std;
或者在main函数前声明命名空间
using namespace std;