c++(72)
-
[C++] 32. 콘솔 글자색 바꾸기
* 위의 표를 보고 해당 색깔의 숫자를 colorNumber에 넣으면 원하는 색깔로 바뀐다!! * 이 기능을 쓰려면 반드시 #include 를 선언해야한다 #include #include // Sleep, system("cls"), SetConsoleTextAttribute 함수를 쓰기위해 포함 using namespace std; // Sleep(밀리초) 밀리초만큼 기다림 // system("cls") 콘솔화면을 지워 줌 // SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 숫자) 글자색바꿈 void SetColor(int colorNumber) { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),..
2022.06.16 -
[C++] 상호참조를 할만한 두 구조체를 만들고 선언부와 구현부를 분리해보자
#include #include using namespace std; // 구조체 선언부 struct Teacher; struct Student; // 구조체 정의부 struct Teacher { string name; int id; string subject; // Teacher 함수 선언부 Teacher(); Teacher(string _name, int _id, string _subject); void Teach(); void ShowInfo(); }; struct Student { string name; int id; int achievement; // Student 함수 선언부 Student(); Student(string _name, int _id, int _achievement); void ..
2022.06.16 -
[C++] 31. 구조체 선언부와 구현부의 분리
1. 구조체로 몬스터와 플레이어를 생성하였고, 각 구조체마다 기능과 속성을 부여하였다. 그 다음 선언부와 구현부를 분리하여 형태를 갖추었다. 함수의 구현부를 작성할때 다음과 같은 연산자를 꼭 추가해주어 어떤 구조체의 함수인지를 표기해야한다 // 함수가 어느 구조체에 있는지 알려주기 위해 :: 연산자 사용 // [문법] 리턴타입 해당구조체::해당함수() #include #include using namespace std; // 선언부와 구현부의 분리 // 구조체의 선언부 : 구조체가 존재한다 struct Monster; struct Player; // 구조체의 정의부 struct Monster { int hp; int atk; // 함수의 선언부 void ShowHp(); void Attack(Player..
2022.06.16 -
[C++] 운송수단을 객체로 구조체를 짜서 상속 및 벡터와 가상함수, 동적할당 쓰기
#include #include #include using namespace std; struct Vehicle { string name; int fuel; Vehicle() { } Vehicle(string _name, int _fuel) { name = _name; fuel = _fuel; } void virtual PrintInfo() { cout
2022.06.15 -
[C++] string / vector / vector+구조체
#include #include using namespace std; void main() { char charText[] = "Hello World"; cout
2022.06.15 -
[C++] 벡터를 사용해서 인벤토리 생성
게임을 만들때 필요한 인벤토리는 필수이다. 인벤토리가 가질 수 있는 기능을 생각해보고 어떤 기능을 넣을것 이고 어떻게 만들 것인가를 구체적으로 생각해야한다. 이는 객체지향이라는 특성을 가진 C++에서 매우 중요한 사고이다. 1. 인벤토리 구조체 만들기 #include #include #include using namespace std; struct Item { string name; Item() { } Item(string _name) { name = _name; } }; struct Player { vector inventory; void PrintInventory() { cout
2022.06.14