I am writing a program to generate a random 16-digit number. My approach is using a character array to store random numbers one by one. Ultimately, I want to convert this character array into a string. How do I do that?
I tried converting it directly to a string but the output gives some weird characters after the 16-digit number when I output it onto the screen.
#include <iostream>
#include <string>
using namespace std;
int main(){
char acct_num[16];
for(int x = 0; x < 16 ; x++){
acct_num[x] = rand()%10 + '0';
}
acct_num[16] = '\0';
cout<<string(acct_num)<<endl;
}
I just want the 16-digit number as a string.