0

10000 を超える乱数を作成し、その数を単語形式で出力する基本的なプログラム。

問題は、そのeNum=atoi(Result[i]);行で、変数についてのコンパイラ エラーが発生することです。std::string

Error:argument of type "char" is incompatible with parameter of type "const char*" 

どういう意味ですか?私はシングルを取ってcharそれをint.

#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <string>
using namespace std;


enum Numbers {Zero, One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Point } eNum;

void main(void)
{
  int iRnd, iTemp;
  string Result;
  iRnd = rand() %  (sizeof(int)-10000) + 10000;
  ostringstream convert;
  convert << iRnd;
  Result = convert.str();

  cout << "\nRandmon number is: " << iRnd << endl << "Converted Number is : " << Result << endl;

  for (int i=0;i<Result.length();i++)
  {
    eNum = atoi(Result[i]);
    cout << eNum; 
    system("pause");
  }
}
4

1 に答える 1

4

このatoi()関数はC文字列を必要とします。コード全体を削除して使用する

int num = atoi(someString.c_str());

変換のため、またはコード内で変更する

eNum = atoi(result[i]);

eNum = result[i] - '0';
于 2012-10-30T06:05:19.587 に答える