Работа с текстом в файле
Добавлено: 07 мар 2010, 18:12
Проверить является ли символ 'С' первым символом каждой строки текста в файле
Код: Выделить всё
#include <iostream>
using std::endl;
using std::cout;
using std::cin;
#include <fstream>
using std::ifstream;
enum ERR{
NOERR=0,
ERROPFILE=1
};
int main(){
ifstream f;
char *s;
bool fl;
s=new char[255];
f.open("in.txt");
if(!f)
return ERROPFILE;
for(fl=0;!f.eof() ;) {
f.getline(s,255);
if(s[0]!='C'){
fl=1;
break;
}
}
cout<<(fl?"NO":"YES")<<endl;
cout<<"press any key to continue: ";
cin.get();
return NOERR;
}
Код: Выделить всё
#include <iostream>
using std::endl;
using std::cout;
using std::cin;
#include <fstream>
using std::ifstream;
enum ERR{
NOERR=0,
ERROPFILE=1
};
int main(){
ifstream f;
char s[255];
int count;
f.open("in.txt");
if(!f)
return ERROPFILE;
for(count=0;!f.eof() ;) {
f.getline(s,255);
count+=s[0]=='C';
}
cout<<count<<endl;
cout<<"press any key to continue: ";
cin.get();
return NOERR;
}