|
读取txt
- #include<fstream>
- #include<string>
- #include<iostream>
- using namespace std;
- void main()
- {undefined
- ifstream in("main.txt");
- string s;
- while(getline(in,s))//着行读取数据并存于s中,直至数据全部读取
- cout<<s.c_str()<<endl;
- }
复制代码- string get_KeyStr(const char* filename)
- {
- std::string str = "";
- std::string temp[3000];
- string infile(filename);
- ifstream fin;
- fin.open(infile, ios::in);
- int i = 0;
- while (fin.good() && i < 3000)
- {
- getline(fin, temp[i]);
- str += temp[i]; // += 已被重载
- i++;
- }
- fin.close();
- return str;
- }
复制代码
参考“
【1】https://blog.csdn.net/qing101hua/article/details/51925204/
|
|