-
dat파일에저장하기TIL(today i learned)/C++ 2020. 10. 4. 18:41
*dat파일이란 2진수로저장되어저있는 파일이다*
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455#include<iostream>#include<fstream>#include<string>#include<vector>using namespace std;class my{public:string one;string two;};int main(void){int count = 0;vector <my>vec;ofstream writeFile;ifstream readFile;string a;string path = "test.dat"; //파일 열기char d[100];readFile.open(path);while (!readFile.eof()){vec.push_back(my());getline(readFile, a);//cout << a << endl;for (int i = 0; i < a.length(); i++){if (a[i] == ' '){count++;continue;}switch (count){case 0:vec.back().one += a[i];break;case 1:vec.back().two += a[i];break;default:break;}}count = 0;}for (vector<my>::size_type i = 0; i < vec.size(); i++){cout << vec[i].one << " " << vec[i].two << endl;}readFile.close();return 0;}cs 'TIL(today i learned) > C++' 카테고리의 다른 글
Flood-Fill algorithm (0) 2020.09.11