목록코딩/C++ (44)
영넌 개발로그

int func_a(int k _)

File 1. binaryfile : (mp3 ...) 2. text file : 노트패드로 열었을 때 사람의 눈으로 알기 쉽게 보이는 파일 (cpp, txt ...) 파일 쓰기 ofstream output file ofstream outFile; ofstream이 하나의 데이터형 (class) outFile.open('text.txt') 열고 쓰기 outFile.close() 닫아야 제대로 기록이 남아있음 예제 실행코드> #define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; int main() { ofstream outFile; outFile.open("yyy.txt"); //사람 이름, 나이, 체중 cout

문자의 종류를 판단하는 함수를 제공 isalnum 알파벳이거나 10진수 해당하는 문자면 1 아니면 0 isalpha 알파벳이면 1 isblank space이거나 tab이면 1 isdigit 숫자(0~9)이면 1 isxdigit 16진수에 사용되는 숫자(0~9,A~F)이면 1 islower 소문자이면 1 isupper 대문자이면 1 isspace 빈칸이면 1 ispunct punctuation 쉼표(,) 마침표(.) 등의 문장기호면 1 tolower 소문자로 바꾸어주는 함수 toupper 대문자로 바꾸어주는 함수 실행파일 > #define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; int main() { char ch; while (tr..

Range based for loop 동적 배열에 대해서는 동작하지 않는다. (방법이 따로 있음) for ( int k : 배열이름) {} 배열 내 데이터 타입 말고 double과 같은 형식으로 써도 저절로 캐스팅 연산 됨 int main() { int a[5] = { 1,2,3,4,5 }; for (int k : a) { cout

inline ? 함수 호출에 따른 overhead를 극복하는 inline 함수를 안쓰고 코드를 복붙한 것처럼 실행되는 것을 의미한다. 함수 반환형 앞에 inline을 적어주면 된다. #include using namespace std; inline double calc_sum(double a, double b) { return (a + b); } int main() { cout

overloading? - over + loading - 같은 함수이름이면서 매개변수의 개수나 타입이 다름 - 함수 반황형은 상관없음 아래와 같이 쓸 경우 오류임 int func_a (int k) void func_a(int k) #define _CRT_SECURE_NO_WARNINGS #include #include using namespace std; struct Person { string name; unsigned int age; }; Person* pdata = 0; bool findPerson(string name) { for (int i = 0; i < 3; i++) { if (pdata[i].name == name) { return true; } } return false; } bool f..

C언어 struct 키워드를 구조체 이름 앞에 꼭 붙여야함 동적으로 구조체 공간 생성을 위해서는 malloc 사용, free로 해제 #include #include struct things { char name[20]; double weight; double price; }; int main() { using namespace std; struct things* pt = (struct things*)malloc(sizeof(struct things)); return 0; } C++ struct 키워드 없이 구조체 이름 만으로도 사용 가능 동적 구조체는 array와 똑같이 new와 delete 사용 #include struct things { char name[20]; double weight; doubl..

Pointer를 이용한 변수 접근 기존 C언어의 방법 int i = 10; int *pi =&i; *pi = 20; C++에서 변수공간을 생성하고 접근하는 방법 new : 공간 생성 (c code - malloc) delete : 공간 해제 (c code - free) #include int main() { using namespace std; int* pi = new int;//별도의 변수를 만들 필요가 없음 //웅앵 delete pi; return 0; } 기존 C언어의 방법 정적 배열 (static array) : 컴파일 단계에서 만들어짐 int pa[10]; C++에서 동적 배열 만들기 dynamic array : 런타임(실행 중) 만들어짐 #include int main() { using nam..

Array, 배열 같은 datatype을 모아둔 것 연속된 공간으로 되어있다. const int arSize = 20; char buf[arSize]; char buf2[20]; 문자열 입력받기 cin.getline( 배열, 최대크기 + null 1개) 줄바꿈이 나오면 그 앞까지 입력한 것들을 복사하고 마지막에 null char도 자동으로 채워줌 배열 : 어느 배열에 넣을 것인지 배열 이름 입력 크기 : 배열 사이즈 #include using namespace std; int main() { const int arSize = 20; char buf[arSize]; //char buf[20] 과 같음 cout