integer to string conversion

237 views
Skip to first unread message

wli

unread,
Jan 19, 2015, 6:15:21 AM1/19/15
to omn...@googlegroups.com
Hi,

How to convert an integer to string in order to use the result as the name of a cMessage, e.g. cMessage *m; m->setName()  I try to use an integer as the name of message m but didn't figure out how to convert the integer into a suitable string type. It seemed that the C function for this purpose atoi() can't be found. I appreciate your help, thanks.

Alfonso Ariza Quintana

unread,
Jan 19, 2015, 6:18:26 AM1/19/15
to omn...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "omnetpp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omnetpp+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

wli

unread,
Jan 19, 2015, 6:33:07 AM1/19/15
to omn...@googlegroups.com, aari...@hotmail.com
Got error message error: ‘to_string’ is not a member of ‘std’. Do I need to specify the C++ version to solve the error, if so how should it be specified in OMNET++ or are there other alternatives. Thanks.

Alfonso Ariza Quintana

unread,
Jan 19, 2015, 6:43:35 AM1/19/15
to omn...@googlegroups.com

Have you included the header?

#include <string>     // std::string, std::to_string

wli

unread,
Jan 19, 2015, 6:47:41 AM1/19/15
to omn...@googlegroups.com, aari...@hotmail.com
Yes I did.

Alfonso Ariza Quintana

unread,
Jan 19, 2015, 7:14:06 AM1/19/15
to omn...@googlegroups.com

Strange, I can compile without problems

 

            std::string str;

            for (int i = 0; i < numQueues; i++)

            {

                str = "wlanDataQueue" + std::to_string(i);

                dataQueue[i].setName(str.c_str());

wli

unread,
Jan 19, 2015, 7:38:07 AM1/19/15
to omn...@googlegroups.com, aari...@hotmail.com
Hi, is to_string() restricted to C++11? The string header file I am using has this indication  'ISO C++ 14882: 21  Strings library', is it an older version? Also I did a search of to_string() but found matches only in file printers.py in the inet folder.

Alfonso Ariza Quintana

unread,
Jan 19, 2015, 8:01:59 AM1/19/15
to omn...@googlegroups.com

http://stackoverflow.com/questions/12975341/to-string-is-not-a-member-of-std-says-so-g

 

I suppose that you are working in Windows with an old version of omnet, there is a problem with to_string in mingw with old versions

wli

unread,
Jan 19, 2015, 8:27:38 AM1/19/15
to omn...@googlegroups.com, aari...@hotmail.com
Reply all
Reply to author
Forward
0 new messages