Hello everyone, I have the source code for this program I'm trying to compile but I'm receiving many errors at this point idk where to start except the first error (knowledge from a guide) ive tried deleting the lines of code that contains the errors but that only seems to lead to more problems. Does anyone have any advice for a beginner? Should I fix the lines of code or delete them? I use cmd gcc compiler, codeblocks, visual studio build tools and visual studio
If you have any advice or willing to help me with this it would be greatly appreciated thanks
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
If your program uses an input file provide the file or a fair sample to work with. It is better that everyone can use the same input information.
When referring to errors post the whole error message, those here get more from the message than you do right now and can help to explain the error message.
Usually it is best to start with the first error message and fix that, recompile and see what is left. Sometimes fixing one error can eliminate several.
Thanks for the fast reply Andy. So here is what I am working with, I have a folder that contains mutiple .cpp and .hpp files. I'm not sure how to use code tags at the moment but I will look into it and post the code here in a few when I get on my laptop. But anyways since they are multiple .cpp files and .hpp files. The first error message I'm getting is stdafx.h: no such file or directory.. which in the first .cpp I'm trying to compile
void Character::DelItem(short id, int amount)
{
int place = -1;
for(unsigned int i = 0; i < inventory.size(); ++i)
{
if(inventory[i].id == id)
{
place = i;
break;
}
}
C:\Users\SESC\Desktop\Test>gcc character.cpp
In file included from character.cpp:1:0:
character.hpp:4:20: fatal error: stdafx.h: No such file or directory
#include "stdafx.h"
^
compilation terminated.
C:\Users\SESC\Desktop\Test>
which is the error should I just delete
#include "stdafx.h" in the character.hpp or do I need to fix this error
Update : I deleted the stdafx.h and it worked but now I'm getting more errors, what should I do? these are the errors I'm getting
eoclient.cpp:199:76: error: expected primary-expression before '>' token
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)
^
eoclient.cpp:199:77: error: '::iterator' has not been declared
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)
^~
eoclient.cpp:199:77: note: suggested alternatives:
In file included from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_algoba
se.h:65:0,
from c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\list:60,
from socket.hpp:15,
from eoclient.hpp:8,
from eoclient.cpp:1:
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_iterator_base_types.h:118:12
: note: 'std::iterator'
struct iterator
^~~~~~~~
c:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\stl_iterator_base_types.h:118:12
: note: 'std::iterator'
eoclient.cpp:199:111: error: 'it' was not declared in this scope
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)
^~
eoclient.cpp:199:117: error: 'handlers' was not declared in this scope
for (std::multimap<std::pair<PacketFamily, PacketAction>, handler_callback>::i
terator it = handlers.begin(); it != handlers.end(); ++it)
^~~~~~~~
eoclient.cpp: At global scope:
eoclient.cpp:255:1: error: 'InitReply' does not name a type
InitReply EOClient::Init(int hdid, int version)
^~~~~~~~~
eoclient.cpp: In member function 'bool EOClient::CreateAccount(std::__cxx11::str
ing, std::__cxx11::string, std::__cxx11::string, std::__cxx11::string, std::__cx
x11::string, std::__cxx11::string)':
eoclient.cpp:316:5: error: 'auto_ptr' is not a member of 'std'
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^~~
eoclient.cpp:316:37: error: expected primary-expression before '>' token
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^
eoclient.cpp:316:39: error: 'reader' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^~~~~~
eoclient.cpp:316:84: error: 'WaitFor' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_ACCOUNT, PACKET_R
EPLY);
^
eoclient.cpp:326:5: error: 'util' has not been declared
util::sleep(3.0);
^~~~
eoclient.cpp:339:27: error: 'util' has not been declared
packet.AddBreakString(util::to_string(hdId));
^~~~
eoclient.cpp: At global scope:
eoclient.cpp:355:50: error: 'Gender' has not been declared
bool EOClient::CreateCharacter(std::string name, Gender gender, Skin skin, shor
t hairStyle, short hairColor)
^~~~~~
eoclient.cpp:355:65: error: 'Skin' has not been declared
bool EOClient::CreateCharacter(std::string name, Gender gender, Skin skin, shor
t hairStyle, short hairColor)
^~~~
eoclient.cpp: In member function 'bool EOClient::CreateCharacter(std::__cxx11::s
tring, int, int, short int, short int)':
eoclient.cpp:357:5: error: 'util' has not been declared
util::sleep(3.0);
^~~~
eoclient.cpp:362:5: error: 'auto_ptr' is not a member of 'std'
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^~~
eoclient.cpp:362:37: error: expected primary-expression before '>' token
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^
eoclient.cpp:362:39: error: 'reader' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^~~~~~
eoclient.cpp:362:85: error: 'WaitFor' was not declared in this scope
std::auto_ptr<ClientPacketReader> reader = WaitFor(PACKET_CHARACTER,PACKET_
REPLY);
^
eoclient.cpp:386:18: error: 'CHARACTER_OK' was not declared in this scope
if(result != CHARACTER_OK) return false;
^~~~~~~~~~~~
eoclient.cpp:402:19: error: 'class Character' has no member named 'admin'
character.admin = static_cast<AdminLevel>(reader->GetChar());
^~~~~
eoclient.cpp:402:39: error: 'AdminLevel' does not name a type
character.admin = static_cast<AdminLevel>(reader->GetChar());
^~~~~~~~~~
eoclient.cpp:411:9: error: 'myCharacters' was not declared in this scope
myCharacters[id] = character;
^~~~~~~~~~~~
eoclient.cpp: In member function 'bool EOClient::RemoveCharacter(std::__cxx11::s
tring)':
eoclient.cpp:422:7: error: 'map' is not a member of 'std'
for (std::map<int, Character>::iterator it = myCharacters.begin(); it != myCha
racters.end(); ++it)
^~~
eoclient.cpp:422:16: error: expected primary-expression before 'int'
for (std::map<int, Character>::iterator it = myCharacters.begin(); it != myCha
racters.end(); ++it)
^~~
eoclient.cpp:422:69: error: 'it' was not declared in this scope
for (std::map<int, Character>::iterator it = myCharacters.begin(); it != myCha
Just so you know this will take me a little while to get into my IDE and tested.
The "stdafx.h" file is a VS 2015 file for precompiled headers. If you use it you need to learn not to. If you are not use to it VS stands for Visual Studio.
When it comes to using code tags read the second link I provided. I have found it explains better.