数値 (12 桁) を文字列として読み取り、それを整数配列にコピーしようとしていますが、うまくいきません。
私のコードはここにあります:
//header files
#include<iostream>
#include<string>
// namespace
using namespace std ;
int main ()
{
string input ;
do
{
cout << "Make sure the number of digits are exactly 12 : ";
cin >> input ;
} while((input.length()) != 12 );
int code[11] ; // array to store the code
//change string to integer
int intVal = atoi(input.c_str());
//
for (int i = 12; i >= 0 ; i--)
{
code[i] = intVal % 10;
intVal /= 10 ;
cout << code[i] ;
}
cout << endl ;
//now display code
for (int i = 0 ; i < 11 ; i++)
{
cout << code[i];
}
system ("pause") ;
return 0 ;
}
したがって、123456789101 の基本的な入力の場合、code[] 配列に格納する必要があります。
したがって、コード ループを表示するときは、123456789101 と同じであることを確認したいと思います。
しかし、それはこれに来ています:
コード中に
for (int i = 0 ; i < 11 ; i++)
{
cout << code[i];
}
それは 00021474836 を示しています。ここに番号を表示したいのです!