반응형
using new with a structure
1.소스
#include <iostream> #include <cstring> using namespace std; struct inflatable { char name[20]; int count; }; int main( int argc , char ** argv ) { string sname = "black falcon"; inflatable *ps = new inflatable; strcpy(ps->name , sname.c_str() ); ps->count = 1; cout << "ps->name " << ps->name << endl; cout << "ps->count " << ps->count << endl; return 0; }
결과
hacker@ubuntu:~/cpp$ !g g++ -o newstract newstract.cpp hacker@ubuntu:~/cpp$ hacker@ubuntu:~/cpp$ hacker@ubuntu:~/cpp$ hacker@ubuntu:~/cpp$ ./newstract ps->name black falcon ps->count 1 hacker@ubuntu:~/cpp$
반응형
'C++ > 0x07-stl' 카테고리의 다른 글
using the delete operator (0) | 2016.07.29 |
---|---|
new (0) | 2016.07.28 |
vector 값 복사 (0) | 2016.07.12 |
erase (0) | 2016.07.12 |
find & erase (0) | 2016.07.12 |