arrays question

My problem is that I'm trying to add parts of an array into a string variable for output. Numeral = _THOUSANDS[thousand] + _HUNDREDS[hundred] + _TENS[ten] + _ONES[one]; That is where I am getting the error "expression must have integral or unscoped enum type error". The arrays are all the same with different chars and they look like this: const char* _HUNDREDS[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; Numeral is a string so it should just add the chars together and form a string that I can easily output. Any insight into my problem would be of great help.
Last edited on
you can't concatenate C-strings (C-strings are char pointers) with operator+. That operation is possible with std::string, so you must change the type of your arrays, or use strcat (a C function).
I've have been looking over std::string and when I try to add it I get massive errors that just freeze my entire visual studio 0.o code before implementing it is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int digit, thousand, hundred, ten, one;
	string Numeral;

	const char* _THOUSANDS[] = {"", "M", "MM", "MMM"};
	const char* _HUNDREDS[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
	const char* _TENS[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
	const char* _ONES[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};

	cout << "Please enter a number: ";
		cin >> digit;

	if (digit <= 3999)
	{
		thousand = digit / 1000;
		digit = digit % 1000;
		hundred = digit % 100;
		ten = digit / 10;
		one = digit % 10;
	
		Numeral = _THOUSANDS[thousand] + _HUNDREDS[hundred] + _TENS[ten] + _ONES[one];
		cout << Numeral;
		system("pause");
	}
}
Like I said, you can't concatenate C-strings like that. Also your procedure to convert the numbers is incomplete.
But you could do:

Numeral = string(_THOUSANDS[thousand]) + _HUNDREDS[hundred + ...

Of course, making them arrays of strings to begin with would probably make more sense.
Topic archived. No new replies allowed.