i cant seem to read the data and assign individual int to an array.
Can i read each digit as a char first, find its position then change it back to an integer?
Can i ask for some help please.
Thanks in advance.
Read in each line as a string using getline(), go though each string and convert each char in the string to an int by doing int k = string[i] - '0', then assign k to the array.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string a;
int arr[81];
int arrcnt =0;//holds current index of array
while(getline(cin, a) && a != "/0"){//store each line in string
for(int i = 0; i != a.size()-1;++i){ //cycle thru char of string
arr[arrcnt] = (a[i]-'0'); //converts from base 16 to int and store in array
cout << arr[arrcnt] << " ";//testing to make sure passed to array properly
++arrcnt;} // up index count
}
return 0;
}