计算机二级c++int转换成string类型代码

2014-11-23 20:06:49 · 作者: · 浏览: 48

  全国计算机等级考试资料下载


  //第一种方法
  #include
  #include
  using namespace std;
  int main()
  {
  int n = 65535;
  char t[256];
  string s;
  sprintf(t, "%d", n);
  s = t;
  cout << s << endl;
  return 0;
  }
  //第二种方法

  #include
  #include
  #include
  using namespace std;
  int main()
  {
  int n = 65535;
  strstream ss;
  string s;
  ss << n;
  ss >> s;
  cout << s << endl;
  return 0;
  }