When I create a hello world it works for me but if I paste a block of code from another site I get that error.
this is my code:
#include <iostream> #include <cstring> using namespace std; struct Node{ char *name; int age; Node(char *n = "", int a = 0){ name = new char[strlen(n) + 1]; strcpy(name, n); age = a; } }; Node node1("Roger", 20), node2(node1); cout << node1.name << ' ' << node1.age << ' ' << node2.name << ' ' << node2.age; strcpy(node2.name, "Wendy"); node2.name = 30; cout << node1.name << ' ' << node1.age << ' ' << node2.name << ' ' << node2.age;
and this error in console:
20:13:22 **** Incremental Build of configuration Debug for project gfr ****
Info: Internal Builder is used for build
g++ -O0 -g3 -Wall -c -fmessage-length=0 -o "src\gfr.o" "..\src\gfr.cpp"
..\src\gfr.cpp:1:21: warning: extra tokens at end of #include directive
#include <iostream> #include <cstring> using namespace std; struct Node{ char *name; int age; Node(char *n = "", int a = 0){ name = new char[strlen(n) + 1]; strcpy(name, n); age = a; } }; Node node1("Roger", 20), node2(node1); cout << node1.name << ' ' << node1.age << ' ' << node2.name << ' ' << node2.age; strcpy(node2.name, "Wendy"); node2.name = 30; cout << node1.name << ' ' << node1.age << ' ' << node2.name << ' ' << node2.age;
^
g++ -o gfr.exe "src\gfr.o"
c:/mingw/bin/../lib/gcc/mingw32/4.9.3/../../../libmingw32.a(main.o):(.text.startup+0xa7): undefined reference to 'WinMain@16'
collect2.exe: error: ld returned 1 exit status
20:13:26 Build Finished (took 4s.313ms)