I am currently learning C++ and I saw there was a line of codes writing on the textbook:
ssize_t num = index; // index could be -1 in the example of my textbook`
The num is a variable to contain the index return from a traversing. However,after I copy this code to my C++ compiler, it says it can not find the definition of ssize_t. And I can hardly find there is any definitions about ssize_t in C++. I saw that it could be use in C but not C++. Right?
>Solution :
ssize_t can (and cannot) be used in C++ just as much as it can (and cannot) be used in C. There is no fundamental type by such name in either language, and there is no ssize_t type in the ISO C standard library, nor is there a std::ssize_t in the C++ standard library.
ssize_t is defined in the POSIX standard. If your program is compiled for a POSIX system, then you can use ssize_t by including the header from the POSIX library that defines it. On non POSIX system, such header doesn’t exist, so this is not portable. You shouldn’t use ssize_t in a cross platform program except in a POSIX specific module that uses the POSIX API.
When you aren’t using the POSIX API, you can typically substitute ssize_t with std::ptrdiff_t.