64,680
社区成员
发帖
与我相关
我的任务
分享
getline(basic_istream<,>& _Istr, basic_stream<,>& _Str);
getline(_Elem* _Str, streamsize _Count);
//下面是glad.h
#ifndef __INCLUDE_FILE_GLAD_H___
#define __INCLUDE_FILE_GLAD_H___
#include<iosfwd>
class sad;
class glad
{
public:
void laugh( std::basic_ostream<char,std::char_traits<char> > & out, sad & other );
void stop( std::basic_ostream<char,std::char_traits<char> > & out);
};
#include "glad_impl.h"
#endif
//上面是glad.h
//下面是sad.h
#ifndef __INCLUDE_FILE_SAD_H___
#define __INCLUDE_FILE_SAD_H___
#include<iosfwd>
class glad;
class sad
{
public:
void cry( std::basic_ostream<char,std::char_traits<char> > & out, glad & other );
};
#include "sad_impl.h"
#endif
//上面是sad.h
//下面是glad_impl.h
#ifndef __INCLUDE_FILE_GLAD_IMPL_H___
#define __INCLUDE_FILE_GLAD_IMPL_H___
#include "glad.h"
#include "sad.h"
#include <iostream>
inline void glad::laugh( std::basic_ostream<char,std::char_traits<char> > & out, sad & other )
{
out << "我很高兴!我笑,我笑!我再笑!!\n";
other.cry( out, *this );
}
inline void glad::stop( std::basic_ostream<char,std::char_traits<char> > & out)
{
out <<"我不笑了。\n" ;
}
#endif
//上面是glad_impl.h
//下面是sad_impl.h
#ifndef __INCLUDE_FILE_SAD_IMPL_H___
#define __INCLUDE_FILE_SAD_IMPL_H___
#include "glad.h"
#include "sad.h"
#include <iostream>
inline void sad::cry( std::basic_ostream<char,std::char_traits<char> > & out, glad & other )
{
out << "我很悲伤,我哭了……\n";
other.stop(out);
}
#endif
//上面是sad_impl.h
[/quote]
参看 #17 的观点。非不能也,实不为也。没必要为了杯水车薪的利益而大动干戈,std::getline 已经挺好了。
_Elem* _Str, streamsize _Count
//下面是glad.h
#ifndef __INCLUDE_FILE_GLAD_H___
#define __INCLUDE_FILE_GLAD_H___
#include<iosfwd>
class sad;
class glad
{
public:
void laugh( std::basic_ostream<char,std::char_traits<char> > & out, sad & other );
void stop( std::basic_ostream<char,std::char_traits<char> > & out);
};
#include "glad_impl.h"
#endif
//上面是glad.h
//下面是sad.h
#ifndef __INCLUDE_FILE_SAD_H___
#define __INCLUDE_FILE_SAD_H___
#include<iosfwd>
class glad;
class sad
{
public:
void cry( std::basic_ostream<char,std::char_traits<char> > & out, glad & other );
};
#include "sad_impl.h"
#endif
//上面是sad.h
//下面是glad_impl.h
#ifndef __INCLUDE_FILE_GLAD_IMPL_H___
#define __INCLUDE_FILE_GLAD_IMPL_H___
#include "glad.h"
#include "sad.h"
#include <iostream>
inline void glad::laugh( std::basic_ostream<char,std::char_traits<char> > & out, sad & other )
{
out << "我很高兴!我笑,我笑!我再笑!!\n";
other.cry( out, *this );
}
inline void glad::stop( std::basic_ostream<char,std::char_traits<char> > & out)
{
out <<"我不笑了。\n" ;
}
#endif
//上面是glad_impl.h
//下面是sad_impl.h
#ifndef __INCLUDE_FILE_SAD_IMPL_H___
#define __INCLUDE_FILE_SAD_IMPL_H___
#include "glad.h"
#include "sad.h"
#include <iostream>
inline void sad::cry( std::basic_ostream<char,std::char_traits<char> > & out, glad & other )
{
out << "我很悲伤,我哭了……\n";
other.stop(out);
}
#endif
//上面是sad_impl.h
#pragma once
#include <istream>
#include <string>
class istreamEx : public std::basic_istream<char, char_traits<char>>
{
public:
_Myt& __CLR_OR_THIS_CALL getline(std::string& str)
{
return *this;
}
};
这样做是没有问题的。