CodeBlock không biên dịch được hàm itoa, stoi trong C++

Em đang sử dụng CodeBlock và khi chuyển kiều int sang string và ngược lại. Em có tìm được tài liệu tham khảo về việc sử dụng 2 hàm itoa và stoi nhưng khi chạy code mẫu trên IDE thì nó báo lỗi

//1

/* itoa example */
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int i;
  char buffer [33];
  printf ("Enter a number: ");
  scanf ("%d",&i);
  itoa (i,buffer,10);
  printf ("decimal: %s\n",buffer);
  itoa (i,buffer,16);
  printf ("hexadecimal: %s\n",buffer);
  itoa (i,buffer,2);
  printf ("binary: %s\n",buffer);
  return 0;
}
error: 'itoa' was not declared in this scope
=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===

http://www.cplusplus.com/reference/cstdlib/itoa/

This function is not defined in ANSI-C and is not part of C++, but is supported by some compilers.

Quá đen rằng gcc/g++ không support cho món này.

3 Likes

Thank you :joy:

Vậy thì có hàm nào chức năng tương tự hay không :slight_smile:

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?