📄 c58.cpp
字号:
// c58.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
void Out();
void InWord();
void InLine();
void InChar();
int main(int argc, char* argv[])
{
Out();
InWord();
InLine();
InChar();
return 0;
}
void Out()
{
ofstream outFile( "text.txt" );
if ( !outFile )
{
cout << "error opening text.txt\n";
exit(1);
}
outFile << "How are you!\n";
outFile << "Find.\n";
}
void InWord()
{
ifstream inFile( "text.txt" );
if ( !inFile )
{
cout << "error opening text.txt\n";
exit(1);
}
char one[64] = "";
cout << "以单词形式显示:\n";
while ( !inFile.eof() )
{
inFile >> one;
cout << one << endl;
}
}
void InLine()
{
cout << "以行的形式显示:\n";
ifstream inFile( "text.txt" );
if ( !inFile )
{
cout << "error opening text.txt\n";
exit(1);
}
char one[80] = "";
while ( !inFile.eof() )
{
inFile.getline( one, sizeof(one) );
cout << one << endl;
}
}
void InChar()
{
cout << "以字符形式显示:\n";
ifstream inFile( "text.txt" );
if ( !inFile )
{
cout << "error opening text.txt\n";
exit(1);
}
char letter;
while ( !inFile.eof() )
{
inFile.get( letter );
cout << letter << " ";
}
cout << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -