📄 正确(改进).cpp
字号:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inClintFile( "new information.txt", ios::in);
//ifstream inClintFile( "new information1.txt", ios::in);
if ( !inClintFile ){
cerr << "File could not be opend\n";
exit(1);
}
/*int count = 0;
char ch;
while (inClintFile >> ch )
{
if ( ch == '@' )
count++;
}
cout << "Email" << count;*/
//char email[137228];
ofstream outClintFile( "email.txt", ios::ate);
if ( !outClintFile ){
cerr << "File could not be opend\n";
exit(1);
}
char a = 'a';
char* ch = &a;
char b = 'b';
char* temp = &b;
char email[150];//数组空间有浪费
int i = 0;
int j = 0;
for(int m = 0; m < 150; m++)
email[m] = ' ';
inClintFile.read(ch, 1);//每次读取一个字符
//以ch作为当前操作的字符,temp作为ch的下一个字符,作用是为了防止最后一个email不能正常输出
while ( inClintFile && !inClintFile.eof() )
//while ( inClintFile.read(ch, 1) )
{
inClintFile.read(temp, 1);//每次读取一个字符
//没有任何email则什么都不输出
//有@则先把@前的存储在数组中,之后存储@,再之后存储@后的但属于email的内容
if ( ( (*ch) != ' ' ) && ( (*ch) != '\n' ) && ( (*ch) != '\t' ) && ( (*ch) != '@' ) ){
email[i] = (*ch);
//cout << email[i];
i++;
if ( email[j] == '@' &&
( (*temp) == ' ' || (*temp) == '\n' ||
(*temp) == '\t' || inClintFile.eof() ) ){//将①处代码合并到此处
//for( ; j < i; j++)
//cout << email[j];
outClintFile.write( email, i);
outClintFile << '\n';
j=0;
for(int k = 0; k < i; k++)
email[k] = ' ';
//cout << '\n';
i = 0;
}
//outClintFile.write( email, 1);
}
else if ( (*ch) == '@' ){
email[i] = '@';
//for(j = 0; j <= i; j++)
//cout << email[j];
j=i;
i++;
}
/*else if ( email[j] == '@' ){ \
//for( ; j < i; j++) |
//cout << email[j]; |
outClintFile.write( email, i); |
outClintFile << '\n'; |
j=0; > ①
for(int k = 0; k < i; k++) |
email[k] = ' '; |
//cout << '\n'; |
i = 0; |
} / */
else {
for(int k = 0; k < i; k++)
email[k] = ' ';
i = 0;
}
//inClintFile.read(ch, 1);
*ch = *temp;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -