atoi()和stoi()的区别

stoi

stoi
stoi() 函数的形参类型是const string*

atoi

atoiatoi() 函数的形参类型是const char*, 可以用c_str()函数进行类型转换。

#include   
#include   
using namespace std;
int main() {

  string s1 = "2147482", s2 = "-214748"; 
  string s3 = "214748666666663", s4 = "-21474836488"; 
  cout << stoi(s1) << endl; 
  cout << stoi(s2) << endl; 
  cout << atoi(s3.c_str()) << endl; 
  cout << atoi(s4.c_str()) << endl; 
  return 0;
}

strncpy

strncpy
strncpy() 函数的形参类型是char*.
reference:
https://blog.csdn.net/yky__xukai/article/details/79554963

你可能感兴趣的:(C++)