This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

itoa (Int to String)

Hey, please excuse the lack of expertise, but it has been years since i've programmed and I am just getting back into it.

I have 2 questions.

1) Why are the standard libraries for Arm different than other standard C libraries. For example, the stdlib library is missing the itoa() function that is available for other compilers. Can I use these libraries for the Arm or do i need one that is specifically made for the Arm compiler. Another example is string.h, where in the past i remember being able to create a variable using the typedef "string" where as in now i cannot.

2) Is there an easy alternative to converting an integer to a string?

Any help is really appreciated.
Thanks
Omer

2)

Parents
  • Don't mention "standard libraries" and itoa() in the same sentence. itoa is not standard.

    There are a number of alternative methods to convert a number to ASCII. The most general is normally sprintf() or snprintf().

    string.h and the datatype string are two completely different entities.

    string.h contains the declarations for use with C-type zero-terminated strings.

    C++ has the std::string data type (previously known only as string) but then you should write

    #include <string>
    

    and not

    #include <string.h>
    

Reply
  • Don't mention "standard libraries" and itoa() in the same sentence. itoa is not standard.

    There are a number of alternative methods to convert a number to ASCII. The most general is normally sprintf() or snprintf().

    string.h and the datatype string are two completely different entities.

    string.h contains the declarations for use with C-type zero-terminated strings.

    C++ has the std::string data type (previously known only as string) but then you should write

    #include <string>
    

    and not

    #include <string.h>
    

Children
  • Thank you PW for your quick response.
    I tried using #include <string> several times with no avail. Each time i get the following errors:

    C:\Keil\ARM\RV31\INC\rw/_defs.h(781): error: #20: identifier "namespace" is undefined
    C:\Keil\ARM\RV31\INC\rw/_defs.h(781): error: #65: expected a ";"
    C:\Keil\ARM\RV31\INC\wchar.h(107): error: #20: identifier "size_t" is undefined
    C:\Keil\ARM\RV31\INC\wchar.h(107): error: #20: identifier "size_t" is undefined
    C:\Keil\ARM\RV31\INC\iosfwd(93): error: #20: identifier "namespace" is undefined
    C:\Keil\ARM\RV31\INC\iosfwd(93): error: #65: expected a ";"

  • Notice that <string> is a C++ include file, and "namespace" is a C++ keyword.

    Are you sure that you are compiling C++ source code, and not C code?

    If you are going to work with C++, I would also recommend that you read up a bit about namespaces, since the C++ runtime library has been moved into the std:: namespace, to follow the current ISO C++ language standard.