1. typedef [기존자료형] [별칭]

예) typedef double salary;


2. using [별칭] = [기존자료형]  (c++11 표준)

예) using salary = double;



int main()
{
	using salary = double;
	using point = int;

	salary bbangwon = 125.20;
	point peter = 100.12;

	return 0;
}
Posted by 빵원군
,
#include "stdafx.h"
#include <fstream>
using namespace std;

int main()
{
	ofstream ofs;

	//file.txt 파일을 연다(없으면 생성).
	ofs.open("file.txt");

	// "This is and apple" 문자열을 파일에 쓴다.
	ofs.write("This is an apple", 16);

	//tellp() 멤버함수를 이용해 파일의 현재 위치를 얻는다.
	//현재 위치는 This is an apple의 맨 끝일 것이다.
	long pos = ofs.tellp();

	//현재 위치에서 7만큼 위치를 뒤로 이동시킨다.
	//현재 위치를 앞뒤로 조정하는 것을 오프셋(offset)을 조정한다고 한다.
	//오프셋을 -7로 조정한 위치는 문자 'n'이다.
	ofs.seekp(pos - 7);

	//조정한 위치부터 문자열 "sam"을 쓴다.
	ofs.write(" sam", 4);

	//파일을 닫는다.
	ofs.close();

	return 0;
}
Posted by 빵원군
,
#include "stdafx.h"
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string str = "파일에씁시다.";
	ofstream ofs("file.txt");	//file.txt 파일을 연다.
	ofs << str;	//file.txt 파일에 str 문자열을 쓴다.
	ofs.close();	//파일을 닫는다.
	ifstream ifs("file.txt");	//file.txt 파일을 다시 열고
	ifs >> str;	//파일의 내용을 str에 저장한다.
	cout << str << endl;	//파일로부터 읽은 내용을 모니터 화면에 출력한다.
	ifs.close();	//파일을 닫는다.
    return 0;
}
Posted by 빵원군
,