编程论坛
注册
登录
编程论坛
→
C++教室
新人学习
lizexu
发布于 2018-01-24 15:05, 1722 次点击
想要在文件中找到自己输入的东西用c++做,并且输出结构体里的其他成分
1 回复
#2
stop1204
2018-01-26 11:30
程序代码:
ifstream infile (
"
D:\\xxxx\\Desktop\\xxxx.txt
"
);
if
(!infile) {
cout
<<
"
openfile error
"
;
return
-
1
;
}
char
ch;
while
(infile.get (ch) ) {
if
(ch !=
'
\n
'
)
cout
<< ch << endl;
else
cout
<<
"
换行
"
;
}
string
str;
while
(getline (infile, str) ) {
if
(str.find (
"
str
"
) != -
1
)
cout
<<
"
found str
"
;
}
1