목록C++ 개념 공부 (48)
Taene's
getline(cin, 문자열을 저장할 string객체, 종결 문자); 최대 문자 수를 입력하지 않아도 된다. 종결 문자를 만날 때 까지 모든 문자열을 입력 받아 하나의 string 객체에 저장한다. cin.getline(변수 주소, 최대 입력 가능 문자수, 종결 문자); 문자 배열이며 마지막 글자가 ‘\0’(terminator)인 c-string을 입력 받는데 사용한다. n-1개의 문자 개수만큼 읽어와 str에 저장한다. (n번째 문자는 NULL(‘\0’)로 바꾼다.) 종결 문자를 별도로 지정해주지 않으면 엔터(‘\n’)로 인식한다. - string의 특정 원소 접근 str.at(index) index 위치의 문자 반환. 유효한 범위인지 체크 O str[index] index 위치의 문자 반환...
#include using namespace std; // //1. 멤버 연산자 함수 버전 //- a op(operation) b 형태에서 왼쪽을 기준으로 실행(a는 클래스이다) //- // //2. 전역 연산자 함수 버전 //- a op b 형태라면, a/b 모두를 연산자 함수의 피연산자로 사용 class Pos { public: Pos()//기본 생성자 { } Pos(int b)//생성자//explicit는 Pos pos1(10)형태만 이 함수로 받아들인다 {//Pos pos1 = 10; 을 못쓰게한다. x = b; y = b; } Pos operator+(const Pos& b)//1. 멤버 연산자 함수 버전 { Pos pos; pos.x = x + b.x; pos.y = y +..
#include #include using namespace std; const int MAX = 100; int board[MAX][MAX]; int N; void PrintBoard() { for (int y = 0; y < N; y++) { for (int x = 0; x < N; x++) { cout
#include using namespace std; void Swap(int& a, int& b) { int c = a; a = b; b = c; } void Sort(int* numbers, int count) { for (int i = 0; i numbers[j + 1]) { Swap(numbers[j], numbers[j + 1]); } } } } void ChooseLotto(int* numbers) { int count = 0; while (count != 0) { int randValue = 1 + rand() % 45;//rand()%45 -> 0~44 //이미 찾..
#include using namespace std; struct StatInfo //스탯인포 구조체는 hp, defense, attack 데이터를 다룬다 { int hp; int defence; int attack; }; StatInfo CreatePlayer() //포인터를 사용하지 않은 함수: StatInfo의 데이터들을 다 복사해와서 사용하므로 데이터의 양이 적을땐 상관없지만, 양이 많아질땐 이렇게 하면 안됨! { StatInfo info; //StatInfo의 데이터들을 다 복사해와서 사용한다. cout hp -= damage; if (monster->hp hp = 0; cout attack - player->defence; if (damage < 0) damage = ..
#include using namespace std; int StrLen(const char* a) { int count = 0; while (a[count] != NULL) count++; return count; } char* StrCpy(char* a, char* b) { char* c = a; int i = 0; while (b[i] != NULL) { a[i] = b[i]; i++; } a[i] = NULL; return c; } char* StrCat(char* a, char* b) { char* c; int lenA = StrLen(a); int i = 0; while (b[i] != NULL) { a[lenA + i] = b[i]; i++; } a[lenA + i] = NULL; retur..