简单的读取文件中的单词

来源:互联网 发布:电吉他效果器软件 编辑:程序博客网 时间:2024/06/05 19:14

#include <iostream>

#include <fstream>

#include <string>

using namespace std;

bool judegChar(char x){

    return((x > 64 && x< 91)||(x >96&& x < 123));

}

int main(){

    ifstreamtext("C:\\text.txt");

    if(text.fail() ){

      cout<< "Can't open test "<< endl;

     return 0;

    }

    charstr[256];

    stringgetstr = "";

   while(text.get(str,256)){

      text.get();

      for(inti = 0;i < 256;i++){

       if(judegChar(str[i])){

           getstr = getstr + str[i];

           if(!judegChar(str[i+1]))

           getstr = getstr + " ";

       }

     }

    }

   cout<< getstr<<endl;

}

0 0