#include
#include
using namespace std;
#ifdef WIN32
#define TEST_FILE "c:\\shi\\aaa.txt"
#else
#define TEST_FILE "/tmp/test.txt"
#endif
//一个字一个字的显示文件内容
void get()
{
ifstream ifs(TEST_FILE);
//while (ifs.good()) cout << (char) ifs.get();//simple
while (ifs.good())
{
char ch = 0;
//ch = ifs.get();
ifs.get(ch);
cout << ch;
}
ifs.close();
}
//一行一行显示文件内容
void getline()
{
//ifstream ifs;
//ifs.open(TEST_FILE);
ifstream ifs(TEST_FILE);
while (ifs.good())
{
char buf[1024] =
{
0
};
ifs.getline(buf, sizeof(buf));
cout << buf << endl;
}
ifs.close();
}
int main(int argc, char* argv[])
{
get();
getline();
return 0;
}
阅读(1179) | 评论(0) | 转发(0) |