📄 text.cpp
字号:
#include<stdio.h>
#include<iostream.h>
#include<string>
#include <fstream >
#include<process.h>
using namespace std;
main()
{
FILE *fp;//打开一个文件
int i=0,j=0,count=0;
char ch;
char *infile;//申请内存变量
infile = new char[1000];
memset(infile,0,1000);//总的作用:将已开辟内存空间 infile 的首 1000 个字节的值设为值 0
string stop[100];
char *outfile;
outfile=new char[1000];
memset(outfile,0,1000);
char rdBuff[100];
if((fp=fopen("D:\\t.txt","r+"))==NULL)
{printf("can not open file!");
exit(0);
}
//将停用词表存放在stop[] 中
// while( !feof(fp) )
printf("打开停用词表:\n");
while( fgets(rdBuff,100,fp)!=NULL )
{
stop[count] = rdBuff;
int m = stop[count].find("\n");//原因:读入了换行。
if(m != string::npos)
{
//cout<<"读入了换行符号!"<<endl;
/*去掉换行符,换行符在stop[i]的末尾!*/
stop[count]=stop[count].substr(0,(stop[count].length() - 1));
}
count++;
printf("%s\n", stop[count - 1].c_str() );//在要求C风格字符串的地方不可直接使用标准库 string 类型对象,返回首地址
}
//把要处理的字符串,以单个字符的形式读到一个char*指向的空间里
printf("\n请输入要处理的字符串:");
ch=getchar();
int pos = 0;
//while(('A'<=ch&&ch<='Z')||('a'<=ch&&ch<='z'))
while(ch!='\n')
{
infile[pos]=ch;
pos++;
ch=getchar();
}
infile[pos]='\0';
printf("\n");
printf("已经读入所输的字符串:%s\n",infile);//查看是否已经把字符串读入到char*指向的空间里
// 比较
int k=1;
for(j=0;j<count;j++)
{
if(stop[j].compare(infile)==0)
{
k=0;
printf("\n%s:是停用词!!!",infile);
printf("\n");
break;
}
}
if(k==1)
{ printf("\n%s:不是停用词!!!",infile);
printf("\n");
strcpy(outfile,infile);
printf("\n%s:已经追加到另一个字符串中!!!\n",outfile);
}
fclose(fp);
delete[] infile;
delete[] outfile;
//return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -