C++笔记

C++读取文件的内容

#include<iostream>
#include <string>  
#include <fstream>  
#include <sstream>  
using namespace std;

string readAnsiTXT(string filename) {

    ifstream fin(filename.c_str());
    if (!fin.is_open()) {
        cout << "open failed!\n";
    }
    char ch;
    string msg = "";
    while (fin.get(ch)) {
        msg += ch;
    }
    return msg;
}

C++判断字符串内容

#include<iostream>
#include <string>  
#include <fstream>  
#include <sstream>  
using namespace std;

bool isContain(string str1, string str2) {

    if (str1.find(str2) != string::npos) {
        return true;
    }
    else {
        return false;
    }
}

posted @ 2022-07-26 20:45  码农阿亮  阅读(39)  评论(0编辑  收藏  举报