每一行读取
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char*argv[])
{
ifstream read_file;
read_file.open("f.txt", ios::binary);
string s;
while(getline(read_file, s))
{
}
return 0;
}
每一个字符读取
void read(string filename){
fstream file;
file.open(filename);
if(!file.is_open()){
cout<<"eror:
}
while(!file.eof())
{
char c;
if(file.good())
{
file>>c;
}
}
}
这里相当于是读取每一个字符,利用文件读写流将值读入c。此时的c就有了值。