輸出程序注釋行
?
#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
;
}

