关于include""与include

#include "basetypes.h"
#include "CfgFile.h"

#include <stdio.h>

#include <sys/timeb.h>


程序自带的头文件,首选“”

系统库的头文件,用<>

阅读更多

自学新手 关于#include与#include及#include的问题

02-04

我按书上的例子编了一个小程序 但出现一些问题 ( 使用C++ 语言 )rn主要是关于#include与#include和#include的运用方面。rn这就是我的程序rn//建立这个类是为了抛出错误rn#ifndef rangeError_Hrn#define rangeError_Hrnrn#include rn#include rnusing namespace std;rnrnclass rangeError rnpublic:rn rangeError( string = "" );rn string what() const;rnprivate:rn string message;rn;rnrn#endifrnrn下面是 rangeError_m.cpp 文件rn#include "rangeError.h"rnrnrangeError::rangeError( string t )rnrn message = t;rnrnrnstring rangeError::what() const rnrn return message;rnrnrn//下面是记录时间的time24类rn#ifndef d_time24_Hrn#define d_time24_Hrnrn//#include rnrn#include //这个还必须要好像它与友元函数的声明有关rn//#include "rangeError.h"rn//using namespace std;rnrnclass time24 rn friend istream& operator>>( istream& istr, time24& t );rn friend ostream& operator<<( ostream& ostr, const time24& t );rn friend time24 operator+( const time24& lhs, const time24& rhs );rnpublic:rn time24( int = 0, int = 0 ) setHour( h ); setMinute( m ); rn void setHour( int ) hour = ( hh >= 0 && hh < 24 ? hh : 0 ); rn void setMinute( int ) minute = ( mm >= 0 && mm < 60 ? mm : 0 ); rn time24 duration( time24 & );rnprivate:rn int hour, minute; //数据成员rn void normalizeTime(); //将时间放在适当的范围中rn;rnrn#endifrnrn下面是 d_time24_m.cpp 文件rn#include "d_time24.h"rnrnvoid time24::normalizeTime()rnrn hour = ( hour >= 0 && hour < 24 ? hour : 0 );rn minute = ( minute >= 0 && minute < 60 ? minute : 0 );rnrnrntime24 time24::duration( time24& t )rnrn int TotalMinutes;rn /*try rn rn if ( ( t.getHour()*60 + t.getMinute() )< ( hour*60 + minute ) )rn throw rangeError( "The punchOutTime Error" );rn rn catch ( const rangeError& t )rn rn cout << t.what() << endl;rn exit( 1 );rn */ 问题就在这里,我想让它们也加入到程序中,问题就出来了。rn TotalMinutes = ( t.hour - hour )*60 - ( t.minute - minute ); rn return time24( TotalMinutes / 60, TotalMinutes % 60 );rnrnrn#include rn#include "d_time24.h"rn//#include "rangeError.h"rn//#include rn/*using namespace;rnusing namespace;*/rnrnint main()rnrn time24 startMovie( 20, 15 ), movieLength( 1, 50 ), endMovie, busArrival( 22, 45 );rn //startMovie是电影开始时间 为20:15rn //movieLength是电影持续时间 为1小时50分钟rn //endMovie是电影结束时间用 time24的友元重载+运算符rn //busArrival是公交到达时间22:45rnrn endMovie = startMovie + movieLength;rnrn cout << "movie ends at " << endMovie << endl;rn //函数duration()是求endMovie和busArrival之间的时间差rn cout << "Waiting time for the bus is " << busArrival.duration( endMovie ) << endl;rn return 0;rnrnrnostream& operator<<( ostream& ostr, const time24& t ) rnrn ostr << ( t.hour < 10 ? "0" : "" ) << t.hour << ':' rn << ( t.minute < 10 ? "0" : "" ) << t.minute;rn return ostr;rnrnrntime24 operator+( const time24& lhs, const time24& rhs )rnrn int TotalMinute;rn TotalMinute = ( lhs.hour + rhs.hour ) * 60 + ( lhs.minute + rhs.minute );rn return time24( TotalMinute / 60, TotalMinute % 60 );rnrnrn各位哥哥姐姐,小弟就是想实现把duration()中的try throw.... catch(...) ... 加到程序中rn结果怎么做都不成功,在反反复复的实验中我得到经验的就是,对于string类要声明#include using namespace std;rn对于cout << string;你同时还要包括#include using namespace std,#include中没有关于它的重载; 但既包含#include又包含#include using namespace std;会出现 cout : ambiguous symbol,但是单用#include using namespace std;好像又出现与有元,ostream和istream有关的错误。rn我想请教各位高手一下如何解决这个问题,问题的本质是什么,我需要补充哪些知识。。。。谢谢,祝大家新年快乐。rnrnrnrnrn

换一批

没有更多推荐了,返回首页