#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char const *argv[])
{
ofstream fout;
fout.open("HelloWorld.txt");//쓰기 스트림열기
string line;
getline(cin, line);
if (!cin.fail())
{
fout << line << endl;
/* code */
}
fout.close();
/* code */
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;
struct Record
{
char text[512];
int id;
};
int main(int argc, char const *argv[])
{
ifstream fin("studentRecords.dat", ios_base::in | ios_base::binary);
if (fin.is_open())
{
Record record;
fin.read((char *)&record, sizeof(Record));// Record크기만큼 읽기
cout << record.text << endl;
cout << record.id << endl;
}
return 0;
}
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
ofstream fout;
fout.open("HelloWorld.txt",
ios::app); // app은 뒤에 데이터 추가 trunc 는 덮어쓰기
string line;
getline(cin, line);
if (!cin.fail()) {
fout << line << endl;
/* code */
}
fout.close();
return 0;
}
절대적
예) 특정한 위치로 감
보통 tellp()/tellg()를 사용해서 기억해 놨던 위치로 돌아갈 때 사용
상대적
예) 특정한 위치로 감
보통 tellp()/tellg()를 사용해서 기억해 놨던 위치로 돌아갈 때 사용
ios_base 네임스페이스를 사용한다.