| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 880 人关注过本帖
标题:getline与<<的错误
只看楼主 加入收藏
jsjljh
Rank: 1
等 级:新手上路
帖 子:9
专家分:3
注 册:2010-3-21
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
getline与<<的错误
#include <fstream>
using namespace std;
void main()
{
   ifstream myIn("a.txt");
   ofstream myOut("b.txt");
   for(string str;getline(myIn,str);)
       myOut<<str<<endl;
}
/* a.txt中的内容是 12 34 56 67 as3
b.txt为空
*/
编译出错:
1>d:\my documents\visual studio 2008\projects\head\head\nafjk.cpp(8) : error C3861: “getline”: 找不到标识符
1>d:\my documents\visual studio 2008\projects\head\head\nafjk.cpp(9) : error C2679: 二进制“<<”: 没有找到接受“std::string”类型的右操作数的运算符(或没有可接受的转换)
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(653): 可能是“std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(700): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(738): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(785): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(909): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(916): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(923): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(930): 或       “std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(170): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(176): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(183): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(190): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(210): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(243): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(263): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 int)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(288): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned int)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(308): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(328): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__w64 unsigned long)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(349): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(369): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(390): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(410): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(430): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(450): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        d:\program files\microsoft visual studio 9.0\vc\include\ostream(470): 或       “std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)”
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        试图匹配参数列表“(std::ofstream, std::string)”时
1>生成日志保存在“file://d:\My Documents\Visual Studio 2008\Projects\Head\Head\Debug\BuildLog.htm”
1>Head - 2 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
请高手帮忙分析一下,谢谢!
搜索更多相关主题的帖子: getline 
2010-03-24 21:06
apull
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:三体星系
等 级:版主
威 望:216
帖 子:1510
专家分:9247
注 册:2010-3-16
收藏
得分:20 
bcc编译正常,运行正常啊。
2010-03-27 15:01
快速回复:getline与<<的错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017994 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved