대단한 동현 블로그
c++ 레퍼런스(참조자)
<language>/c++ 2023. 7. 6. 18:56

// 포인터와 레퍼런스의 차이를 알아보는 코드이다. intmain() { std::stringstr = "HI THIS IS BRAIN"; std::string*stringPTR; std::string&stringREF = str; // 레퍼런스는 선언하면서 초기화 해줘야 한다. stringPTR = &str; // 주소 출력부 std::cout

c++ 동적할당
<language>/c++ 2023. 7. 6. 18:53

//객체의 포인터를 반환하는 함수이다. Zombie* newZombie(std::string name) { Zombie *zom = new Zombie(name); return (zom); } cpp에서 동적할당을 하고 싶을 땐 객체이름 *이름 = new 생성자(arg); 이런식으로 한다. //객체 배열 포인터를 반환하는 함수이다. Zombie* zombieHorde( int N, std::string name ) { Zombie *zom = new Zombie[N]; for (int i = 0; i < N; i++) zom[i].setName(name); return (zom); } 객체 배열을 동적할당 할 땐 생성자 안에 arg를 직접 넣을 수가 없다. 만든 후에 초기화 해 주는 모습이다. intma..

cpp 파일 컨트롤(ifstream ofstream)
<language>/c++ 2023. 7. 5. 12:53

C++의 헤더에 정의된 ifstream와 ofstream 클래스는 파일의 입력 및 출력 작업을 담당합니다. ifstream는 파일로부터 데이터를 읽는 데 사용되고, ofstream는 파일에 데이터를 쓰는 데 사용됩니다. 아래에 각 클래스의 기본 사용법을 설명하겠습니다. ifstream 사용 방법: 헤더 파일을 포함시킵니다: #include ifstream 객체를 선언하고 파일을 엽니다: ifstream inputFile("파일명"); 파일을 열었는지 확인합니다: if (inputFile.is_open()) { // 파일이 열렸을 때 수행할 작업을 여기에 작성합니다. } else { // 파일을 열지 못했을 때 수행할 작업을 여기에 작성합니다. } 파일에서 데이터를 읽습니다: int number; inpu..

프로그래머스 네트워크 c++

https://school.programmers.co.kr/learn/courses/30/lessons/43162 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; vector v; vector com; int nn; // 1 1 0 // 1 1 0 // 0 0 1 void recur(int i) // 인덱스 하나씩 순회하면서 { for (int j = 0; j < nn; j++) { if (v[j] && com[i][j]) { // i, j 가 연결되어 있으면 v[j] =..

프로그래머스 타겟넘버 c++

https://school.programmers.co.kr/learn/courses/30/lessons/43165 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; vector num; int targ, answer; void recur(int idx, int res) { if (idx == num.size()) { if (res == targ) answer++; return ; } recur (idx + 1, res - num[idx]); recur (idx + 1, res + num[i..

프로그래머스 뉴스 클러스터링 c++

https://school.programmers.co.kr/learn/courses/30/lessons/17677 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include #include #include using namespace std; void setMap(unordered_map &map, string str, unordered_set &set) { for (int i = 0; i < str.size() - 1; i++) { string s = str.substr(i, 2); if (!islower(s[0]) ..