重载operator<<问题..标准库和vcl如何转化?ostream<

destructor 2003-10-17 11:51:39
相关代码如下

错误:
friends must be functions or classes..
加入std::后,会提示未定义std:opeartor<<ansistring

#include <ostream>
#include <string>
#include <iostream>
#include <sysvari.h>
#include <vcl.h>

//---------------------------------------------------------------------------
class TTimeScope {
private:
TTime _startTime;
TTime _endTime;
protected:
public:
friend ostream& operator<< ( ostream& out, const TTimeScope& timeScope ) ;
};

//---------------------------------------------------------------------------

ostream& operator<< ( ostream& out, const TTimeScope& timeScope )
{

out << std::string(timeScope._startTime.FormatString("hh:nn").c_str()) ;
out << "至" ;
out << timeScope._endTime.FormatString("hh:nn") ;
return out ;
}
...全文
149 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ljianq 2003-10-17
  • 打赏
  • 举报
回复
ostream& operator<< ( ostream& out, const TTimeScope& timeScope )
{

out << timeScope._startTime.FormatString("hh:nn").c_str() ;
out << "至" ;
out << timeScope._endTime.FormatString("hh:nn")").c_str() ;
return out ;
}

destructor 2003-10-17
  • 打赏
  • 举报
回复
分特,没看到最后一文,偶当然看帮助,不然哪会加这两个头文件
#include <iostream>
#include <sysvari.h>

和你说的define功能相当
Thor_Cascades 2003-10-17
  • 打赏
  • 举报
回复
你从不看帮助的吗?AnsiString可以直接输出的
只是要加一个#define什么东西
在AnsiString帮助的第一页就有
destructor 2003-10-17
  • 打赏
  • 举报
回复
你这个肯定不行,会提示friends must be functions or classes
其实就是ostream未定义之类的,假如用std::ostream当然可以
用std::ostream我的第一个也成,只是每个都需要c_str(),觉得不爽啊

604

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder VCL组件使用和开发
社区管理员
  • VCL组件使用和开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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