C++/0x07-stl
using new with a structure
SpeeDr00t
2016. 7. 29. 13:56
반응형
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$
반응형