当了2个学期的TA,改作业的时候, 记录下来一些东西
写一个function, 如下, 但是当out fail的时候, 必须返回false.
有以下的一些方法。
(1)
bool bad_word(string word, int line, ostream& out)
{
out<<word<<....;
if (out.fail())
{
return false;
}else
{
return true;
}
}
(2)
bool bad_word(string word, int line, ostream& out)
{
if(out<<word<<.... ){
return true;
}
return false;
}
(3)
bool bad_word(string word, int line, ostream& out)
{
ostream& watcher=out<<word<<....;
if(watcher){
return true;
}
return false;
}
int main()
{
bad_word(..., cout);
bad_word(..., ofile);
bad_word(..., oss);
.....
}
写一个function, 如下, 但是当out fail的时候, 必须返回false.
有以下的一些方法。
(1)
bool bad_word(string word, int line, ostream& out)
{
out<<word<<....;
if (out.fail())
{
return false;
}else
{
return true;
}
}
(2)
bool bad_word(string word, int line, ostream& out)
{
if(out<<word<<.... ){
return true;
}
return false;
}
(3)
bool bad_word(string word, int line, ostream& out)
{
ostream& watcher=out<<word<<....;
if(watcher){
return true;
}
return false;
}
int main()
{
bad_word(..., cout);
bad_word(..., ofile);
bad_word(..., oss);
.....
}