g++ À» ÀÌ¿ëÇØ¼ È£½ºÆ® À̸§À» Ãâ·ÂÇÏ´Â Å×½ºÆ® ÇÁ·Î±×·¥ÀÔ´Ï´Ù.
ÄÄÆÄÀÏ : g++ -o test test.cpp
¼Ò½º
#include <unistd.h> #include <string> // Ŭ·¡½º¸¦ ¼±¾ðÇϳª. class Init { private: public: static string get_hostname(); }; // get_hostname À̶ó´Â ÇÔ¼ö¸¦ ¸¸µé¾î ÁØ´Ù. string Init::get_hostname() { char buf[128]; // È£½ºÆ® À̸§ÀÌ µé¾î°¥ º¯¼ö¸¦ ¼±¾ð string ret; // È£½ºÆ® À̸§À» ¾ò´Â ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù. if((gethostname ( buf, sizeof(buf) )) < 0) { ret.assign("Unkown Hostname"); // È£½ºÆ® À̸§ÀÌ ¾øÀ» °æ¿ì } else { ret.assign(buf); // È£½ºÆ® À̸§À» ¾ò¾úÀ» °æ¿ì } return ret; // °á°ú °ªÀ» ¸®ÅÏÇÑ´Ù. } int main(void) { cout << Init::get_hostname() << endl; // ȸ鿡 Ãâ·ÂÇÑ´Ù. } |
¼Ò½º
#include <string> // Hello °´Ã¼¸¦ ¸¸µç´Ù. class Hello { private: public: // ÇÔ¼ö¸¦ Çϳª ¸¸µç´Ù. void displayData() { cout << "I am class" << endl; // Ãâ·ÂÀ» ÇÑ´Ù. } }; int main(void) { Hello hello; //hello °´Ã¼¸¦ ¼±¾ðÇÑ´Ù. hello.displayData(); //Ãâ·ÂÇÑ´Ù. } |
°á°ú
I am class |