Amway a black out of their own technology

One day zjq chicken dishes have nothing else (is okay for some purposes, but not good to tell you), will engage in a patchwork of code

This code can be convenient for the search process for a number of documents, and has good scalability (well what this means is zjq only broke a search function)

In fact, a similar function in almost every document software which has, however, when more and more number of files when they open just enough to document editing software crashes ... not to mention the batch search

So we find a way myself ...

Reason, we engage in OI (bald) sector Zeneng will not be able to facilitate the life of small point does it ...

However, it really does not goose, so he can search the Internet to achieve various methods of operation, for example, get a bunch of file names, and to find specific content in these documents (although the latter we also got to get yourself together. .. but maybe efficient online method it! Although the difference in the efficiency of the final and did not find ... but we still shining engage in law to the internet ...)

Ever since a document batch search on the specified content codepotThe furnace!

//by Judge
#include<bits/stdc++.h>
#include<io.h>
using namespace std;
vector<string> files; char str[30]; string s;
char filePath[999]="E:\\Test";
void getFiles(string path,vector<string>& files){
    long nowFile=0; string p;
    struct _finddata_t fileinfo;
    if((nowFile=_findfirst(p.assign(path).append("\\*").c_str(),&fileinfo))!=-1){
        do{
            //如果是目录,向下迭代 
            if((fileinfo.attrib&_A_SUBDIR)){
                if(strcmp(fileinfo.name,".")!=0&&strcmp(fileinfo.name,"..")!=0)
                    getFiles(p.assign(path).append("\\").append(fileinfo.name),files);
            } else //否则加入列表 
                files.push_back(p.assign(path).append("\\").append(fileinfo.name));
        }while(_findnext(nowFile,&fileinfo)==0);
        _findclose(nowFile);
    }
}
inline bool Find(char* s,string obj){
    ifstream fi(s,ofstream::in); string buf;
    if(fi.is_open()){
        while(fi>>buf) if(buf.find(obj)!=-1) return 1;
        fi.close();
    } return 0;
}
int main(){
    getFiles(filePath, files ); //获取该路径下的所有文件 
    int size = files.size();
//  有需要的可以直接输出所有带路径的文件名 
//  for (int i = 0;i < size;i++)
//      cerr<<files[i].c_str()<<endl;
    string object="Judge";
    char str[999]; int cnt=0;
    for(int i=0;i<size;++i){
        strcpy(str,files[i].c_str());
        if(Find(str,object))
            cerr<<files[i].c_str()<<endl,++cnt;
    }
    if(cnt>0) cerr<<"Find "<<cnt<<" Result!"<<endl;
    else cerr<<"Failed Find Any Thing!!!"<<endl;
    return 0;
}

So Nepal can use this code is easy to find a bunch ofFiction The content of the document inside spicy ~ QWQ (did not realize that they exposed what the zjq)

How to achieve specific we not say, OIer although they themselves may not play out, but learning (or understand?) What the code than white, but still has a big advantage of it ...

But taking into account the real white may not understand the code for this .... QWQ

So we talk a little usage (achieved speak Ghosts, which bunch of functions we do not know exactly is wisdom for the good cutting?):

First, the Di Liu told that behind the line of string filePath (Yes, that's "E: \ Test") to change the path you want to search folders (just look like a copy in a folder above the address bar ), a little note here a bit, is to slash two, because ... hey, OIer can understand themselves, others say we also futile ... anyway, a backslash into two like slightly

The second is the first main function inside the six with the object behind the line of string (yes, that "Judge") into what you want to search for (can be Chinese, in addition to the above path which can also have a Chinese)

The last is the most important, if you are not engaged in C ++, and was put on a dev cpp ... this, we give a total installed link okay ... we are not taught ... Address Click here

Incidentally a welcome discovery: chicken dish zjq the two characters stored char int turn outputs surprised to find that they are negative, perhaps this is the way the characters stored characters ... and you can save 17 kinds of Chinese characters about 2, far more than the total number of words of Chinese characters (of course, the Ming Dynasty that are created characters one by one giant man of nobility to engage in out of the immortal words we do not enumerated, Kazakhstan, though enumerated, should also be put under QWQ)

ojbk ... Originally I wanted to get this thing up csdn sell, but finally felt good out to share, by the way: without the consent of the author, please do not spread this code ... (of course URL can be shared da ~)

Seeking recommendations, seeking collection, seeking to share ღ ( '· ᴗ · `)

Guess you like

Origin www.cnblogs.com/Judge/p/11233813.html