본문 바로가기
반응형

Computer Languages/C | C++13

string::getline string의 getline함수는 cin으로 입력받을때 공백도 같이 입력받을수 있다. [예제] // string_getline_sample.cpp // compile with: /EHsc // Illustrates how to use the getline function to read a // line of text from the keyboard. // // Functions: // // getline Returns a string from the input stream. ////////////////////////////////////////////////////////////////////// #pragma warning(disable:4786) #include #include using names.. 2010. 11. 19.
string을 char로 취급하기 #include #include using namespace std; int main() { string name; cin >> name; cout 2010. 10. 21.
[펌]private, proteted, public 의 차이 부모 클래스의 속성 상속 속성 상속 시 속성 private private private private protected private private public private protected private private protected protected protected protected public protected public private private public protected protected public public public 위 표와 같이 private를 어떤 속성으로 상속하든 결과는 private가 되며, protectec는 상속되는 속성에 따라 private 또는 protected가 된다. 그리고 public 또한 상속되는 속성에 따라 private, protected, publ.. 2010. 10. 12.
[펌] new와 delete 메모리를 동적으로 할당하고 해제하기 위해 C에서 malloc과 free가 있었다. C++에서는 new와 delete를 사용한다. - new 연산자를 사용할 경우 명시적 형변환을 할 필요가 없다. int *p=(int *) malloc(sizeof(int)); // 4바이트 할당 int *p=(int *) malloc(sizeof(int)*3); // 12바이트(int형 3개를 갖는 배열) 할당 int *p=new int; // 4바이트 할당 int *p=new int[3]; // 12바이트(int형 3개를 갖는 배열) 할당 - 메모리 할당과 동시에 초기화가 가능하다(단, 배열 형태로 할당받을 경우에는 초기화가 여전히 불가능). int *p=new int(100); // int형 변수 하나를 할당받으면서 .. 2010. 10. 11.
728x90