itt' is not recognised

Asked

Viewed 453 times

2

I am trying to compile the code below with GCC 4.7.4, but always get the bug

error: ạ itoa' was not declared in this Scope

#include "otpch.h"
#include <iomanip>
#include <stdlib.h>
#include <boost/config.hpp>
#include <boost/bind.hpp>

#include "iomap.h"
#include "map.h"
#include "tile.h"

#include "creature.h"
#include "player.h"
#include "combat.h"

#include "iomapserialize.h"
#include "items.h"

#include "game.h"
#include "configmanager.h"

[...]

    bool Map::placeCreature(const Position& centerPos, Creature* creature, bool extendedPos /*= false*/, bool forced /*= false*/)
{
    Monster* monster = creature->getMonster();
    if(monster && g_config.getBool(ConfigManager::MONSTER_HAS_LEVEL))
    {
        uint8_t level;
        if(!monster->getMonsterType()->hideLevel)
        {
            if(monster->isSummon())
            {
                std::string value;
                monster->getMaster()->getStorage((std::string)"monster_level", value);

                uint8_t intValue = atoi(value.c_str());
                if(intValue || value == "0")
                    level = intValue;
                else
                    level = 1;
            }
            else
                level = monster->level;

            char buffer [10];
            monster->name = monster->getName() + " [PDL : " + itoa(level, buffer, 10) + "]";
        }
    }
    bool foundTile = false, placeInPz = false;
    Tile* tile = getTile(centerPos);
    if(tile && !extendedPos)
    {
        placeInPz = tile->hasFlag(TILESTATE_PROTECTIONZONE);
        uint32_t flags = FLAG_IGNOREBLOCKITEM;
        if(creature->isAccountManager())
            flags |= FLAG_IGNOREBLOCKCREATURE;

        ReturnValue ret = tile->__queryAdd(0, creature, 1, flags);
        if(forced || ret == RET_NOERROR || ret == RET_PLAYERISNOTINVITED)
            foundTile = true;
    }

    size_t shufflePos = 0;
    PairVector relList;
    if(extendedPos)
    {
        shufflePos = 8;
        relList.push_back(PositionPair(-2, 0));
        relList.push_back(PositionPair(0, -2));
        relList.push_back(PositionPair(0, 2));
        relList.push_back(PositionPair(2, 0));
        std::random_shuffle(relList.begin(), relList.end());
    }

    relList.push_back(PositionPair(-1, -1));
    relList.push_back(PositionPair(-1, 0));
    relList.push_back(PositionPair(-1, 1));
    relList.push_back(PositionPair(0, -1));
    relList.push_back(PositionPair(0, 1));
    relList.push_back(PositionPair(1, -1));
    relList.push_back(PositionPair(1, 0));
    relList.push_back(PositionPair(1, 1));
    std::random_shuffle(relList.begin() + shufflePos, relList.end());

    uint32_t radius = 1;
    Position tryPos;
    for(uint32_t n = 1; n <= radius && !foundTile; ++n)
    {
        for(PairVector::iterator it = relList.begin(); it != relList.end() && !foundTile; ++it)
        {
            int32_t dx = it->first * n, dy = it->second * n;
            tryPos = centerPos;

            tryPos.x = tryPos.x + dx;
            tryPos.y = tryPos.y + dy;
            if(!(tile = getTile(tryPos)) || (placeInPz && !tile->hasFlag(TILESTATE_PROTECTIONZONE)))
                continue;

            if(tile->__queryAdd(0, creature, 1, 0) == RET_NOERROR)
            {
                if(!extendedPos)
                {
                    foundTile = true;
                    break;
                }

                if(isSightClear(centerPos, tryPos, false))
                {
                    foundTile = true;
                    break;
                }
            }
        }
    }

    if(!foundTile)
        return false;

    int32_t index = 0;
    uint32_t flags = 0;

    Item* toItem = NULL;
    if(Cylinder* toCylinder = tile->__queryDestination(index, creature, &toItem, flags))
    {
        toCylinder->__internalAddThing(creature);
        if(Tile* toTile = toCylinder->getTile())
            toTile->qt_node->addCreature(creature);
    }

    return true;
}
  • Try to use it like this: string(itoa(level, buffer, 10))

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

1

I’ll respond based on the information you’re passing on. I do not know if you will be able to apply since you are having very basic difficulties to use the compiler.

It looks like you are using a new version enough to use better features available in the language. So instead of using the itoa, use the std::to_string(), then replace

itoa(level, buffer, 10)

for

std::to_string(level)

And the atoi may also be replaced by std::stoi() then replace:

atoi(value.c_str());

for

std::stoi(value)

I put in the Github for future reference.

Remembering that the answer works if the past information is correct. If I can improve the information of the question I can improve the answer.

  • How can I improve my information ?

  • After the issues I don’t know if you’re gonna make it. I realize you’re trying to mess with something complex without getting a sense of how these things work. There will probably be many other similar problems and you will give up. I don’t want to discourage you but without you trying to understand the workings of what you’re doing you won’t be able to proceed. Initially I thought you were doing some simple exercise. For those who are starting, solving something simple is easier, solving complex codes is unfeasible. This I passed, solved?

  • I’m compiling again gave of lack of libs, and about giving up ? I am studying this source for almost 1 year and I already understand a lot, however always appears this joke , summarizing I remove the modification that I did more do not give up ! of course if I can solve it would be better :D

  • error: ‘to_string’ is not a member of ‘std’ ///// /usr/include/boost/exception/to_string.hpp:72:5: note: ‘boost::to_string’&#xA; to_string( std::pair<T,U> const & x )

  • Try compiling with -std=c++11. Do you realize that even though you’ve been messing with this for a year, you’re slipping into some pretty basic stuff? You’re probably trying to climb the ladder starting from the top steps, it doesn’t usually work.

  • Yes, but I couldn’t find a course in my city so I have to go online :/

  • gcc version 4.7.4 (Ubuntu/Linaro 4.7.4-2ubuntu1) my version and even so does not recognize :/

  • No, the purpose of website is not this. You can start looking for basic information first, buy books, see basic classes on the Internet, and then go after sophisticated things. Here’s a tip: http://answall.com/tags/c%2b%2b/info If you know English, it’s easy. Programming without knowing English, complicates. You said the version was 4.9.1, now it has regressed? There is something wrong there. I based myself on what you had informed. With wrong information it is difficult to answer right. Can you update it? It would be better to work with the latest versions.

  • See working: http://ideone.com/KZCgkx

  • This solution http://answall.com/a/45043/101can also be used

  • How do I update my c++ to 11 linux?

  • This is another question, opens another question to this. Here is not a forum.

  • None works, to work need to update the c++

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.