huidong

首页 | 会员登录 | 关于争取 2022 寒假做出汇东网 Ver3.0.0 !
搜索文章


#include <stdio.h>
#include <conio.h>
#include <string>
#include <vector>
#include <fstream>
#include <streambuf>
using namespace std;

// 获取文件内容
string GetFile(const char* filepath)
{
    ifstream t(filepath);
    string str((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());
    t.close();

    if (str.size() <= 0)
    {
        printf("\n\nopen %s error.", filepath);
        _getch();
        exit(-1);
    }

    return str;
}

// 是否为英文字母(或空格)
bool isEnglishAlphabet(char c)
{
    return (c >= 65 && c <= 90) || (c >= 97 && c <= 122);
}

vector<string> Load(string res)
{
    vector<string> list;
    string name;
    for (int i = 0; i < (int)res.size(); i++)
    {
        if (isEnglishAlphabet(res[i]))
        {
            name += res[i];
        }
        else if (name.size() > 0)
        {
            list.push_back(name);
            name = "";
        }
    }
    return list;
}

int main()
{
    vector<string> list = Load(GetFile("t.txt"));
    
    for (int i = 0; i < (int)list.size(); i++)
    {
        printf("%s\n", list[i].c_str());
    }
    _getch();

    return 0;
}




返回首页


Copyright (C) 2018-2024 huidong