error C2679: 二进制“>>”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)

jjlovedaisy 2009-11-09 10:51:32
// test_string.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include "String.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

int aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0,
theCnt = 0, itCnt = 0, wdCnt = 0, notVowel = 0;
// 为了使用operator==( const char* )
// 我们并不定义The( "The" )和It( "It" )
string buf, the( "the" ), it( "it" );
// 调用operator>>( istream&, String& )
while (cin >> buf) {
++wdCnt;
// 调用operator<<( ostream&, const String& )
cout << buf << ' ';
if ( wdCnt % 12 == 0 )
cout << endl;
// 调用String::operator==(const String&) and
// String::operator==( const char* );
if ( buf == the || buf == "The" )
++theCnt;
else
if ( buf == it || buf == "It" )
++itCnt;
// 调用String::size()
for ( int ix = 0; ix < buf.size(); ++ix )
{
// 调用String::operator[](int)
switch( buf[ ix ] )
{
case 'a': case 'A': ++aCnt; break;
case 'e': case 'E': ++eCnt; break;
case 'i': case 'I': ++iCnt; break;
case 'o': case 'O': ++oCnt; break;
case 'u': case 'U': ++uCnt; break;
default: ++notVowel; break;
}
}
}
// 调用operator<<( ostream&, const String& )
cout << "\n\n"

<< "Words read: " << wdCnt << "\n\n"
<< "the/The: " << theCnt << '\n'
<< "it/It: " << itCnt << "\n\n"
<< "non-vowels read: " << notVowel << "\n\n"
<< "a: " << aCnt << '\n'
<< "e: " << eCnt << '\n'
<< "i: " << iCnt << '\n'
<< "o: " << oCnt << '\n'
<< "u: " << uCnt << endl;


return 0;
}

error C2679: 二进制“>>”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)

报错误 请大家帮忙
...全文
4541 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ailoverer 2012-10-28
  • 打赏
  • 举报
回复
一楼正解
wizard_tiger 2012-06-09
  • 打赏
  • 举报
回复
一楼正解!
晚安苏州 2012-06-05
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

把#include "String.h"
改成#include<string>
[/Quote]
+
guoguangjian2011 2012-06-05
  • 打赏
  • 举报
回复
"string.h"是C语言中的用法,没有运算符的重载,而C++中用<string>,新添了运算符的重载
harizu76 2009-12-23
  • 打赏
  • 举报
回复
vc60可以通过的
KaKaKaKa 2009-12-22
  • 打赏
  • 举报
回复
用#include <string>,String.h是老版本的
herry-Li 2009-12-22
  • 打赏
  • 举报
回复
cout < < "\n\n 注意< <中间的空格。去掉空格即ok
lyxnina1986 2009-12-19
  • 打赏
  • 举报
回复
把#include "String.h"
改成#include<string>

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧