fstream 함수를 사용하여 .txt 파일에서 일부 텍스트를 읽는 데 사용되는 C ++ 프로그램이 있습니다. 그러나 출력 화면에는 원하지 않는 while 루프의 추가 출력이 표시되므로 tt.txt에 데이터가 포함되어 있으면
ss
123
출력은
Name ss
roll no 123
name
roll 123
암호:
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<string.h>
#include<stdio.h>
void student_read()
{
clrscr();
char name[30];
int i,roll_no;
ifstream fin("tt.txt",ios::in,ios::beg);
if(!fin)
{
cout<<"cannot open for read ";
return;
}
while(!fin.eof())
{
fin>>name;
cout<<endl;
fin>>roll_no;
cout<<endl;
cout<<"Name is"<<"\t"<<name<<endl;
cout<<"Roll No is"<<roll_no<< endl;
}
}
void main()
{
clrscr();
cout<<"Students details is"<<"\n";
student_read();
getch();
}
I / O에 대한 도움말은 C ++ FAQ를 참조하십시오. http://www.parashift.com/c++-faq/input-output.html
#include <iostream>
#include <fstream>
void student_read() {
char name[30];
int roll_no;
std::ifstream fin("tt.txt");
if (!fin) {
std::cout << "cannot open for read ";
return;
}
while(fin >> name >> roll_no) {
std::cout << "Name is\t" << name << std::endl;
std::cout << "Roll No is\t" << roll_no << std::endl;
}
}
int main() {
std::cout << "Students details is\n";
student_read();
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다