road420

导航

<2008年1月>
303112345
6789101112
13141516171819
20212223242526
272829303112
3456789

统计

常用链接

留言簿(2)

随笔档案

文章档案

搜索

最新评论

阅读排行榜

评论排行榜

输出程序注释行

 

#include < iostream >
#include
< fstream >
#include
< vector >
#include
< string >
#include
< stdexcept >
using   namespace  std;

void  read( const   string  name);

void  read( const   string  name)
{
ifstream file;
char  ch;
char   * s = new   char ();
file.open(name.c_str());
// 讲string类型转换为字符串类型
if (file.fail())
{
  
throw  invalid_argument(name);
}

while ( ! file.eof())
{
 
int  i = 0 ;
 file.
get (ch);
 
while (ch != ' / ' )
   file.
get (ch);
 file.
get (ch);
 
if (ch != ' * ' )
   
continue ;
 
else
  file.
get (ch);
  
while (ch != ' * ' )
 
{
  s[i
++ ] = ch;
  file.
get (ch);
 }

 file.
get (ch);
 
if (ch == ' / ' )
 

  cout
<< s << endl;
  cout
<< flush;
  
for ( int  j = 0 ;j < i;j ++ )
    s[j]
= ' * ' ;
 }

 
else
  
continue ;
}

file.close();
 delete s;
}


int  main()
{
const   string  fname = " 1.txt " ;
try {
 read(fname);
}
catch ( const  invalid_argument &  e                                                                                                                                                                         ) {
  cerr
<< " 不能打开该文件 " << fname << endl;
  exit(
1 );
}
catch ( int  e) {
   cerr
<< " 语法错误 " << endl;
   exit(
1 );
}

return   0 ;
}



posted on 2006-05-09 22:08 深邃者 阅读(354) 评论(1)  编辑 收藏 引用

评论

# re: 输出程序注释行 2013-07-23 17:27 岁月漫步

没看懂什么意思  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理