+ 7
Can I make an array with both numbers and characters
Is it possible in c++
3 Réponses
+ 2
array can store only one type of things
but you can convert your chars to ints with (int)ch and put it in the array, because characters are internally stored as numbers
+ 5
struct numcharvec
{
std::vector<int> nums;
std::vector<char> chars;
}
+ 2
You may try an array of a union :
union Spl{short i; char c;};
int main()
{
array<Spl,5> arr = {1,'2',32,'a','e'};
cout<<arr[3].c; // Prints a.
}