Исключением является "Исключение, выданное в 0x0F71514F (vcruntime140d.dll) в ConsoleApplication28.exe: 0xC0000005: Произошло нарушение записи о местоположении доступа 0xCCCCCCCC."
Кажется, что-то связано с тремя строками
lowerOutput = twoColumn[i][1];
lowerOutputSecond = toLower(lowerOutput);
twoColumn[i][2] = lowerOutputSecond;
и я не могу понять, в чем проблема.Я могу вынуть эти строки, и это работает нормально, хотя и не полностью.Любая помощь будет оценена.
#include <iostream>
#include <string>
using namespace std;
string toLongRoman(int a);
string toLower(string s);
int main() {
int input = 1, error = 1, oneColumn[35];
string lowerOutput, lowerOutputSecond, twoColumn[35][2];
do {
cout << "Please enter a number between 1 and 5000: ";
cin >> input;
if (input >= 1 && input <= 5000) {
error = 0;
break;
}
else {
cout << "Invalid input, try again." << endl;
error = 1;
cin.clear();
cin.ignore(80, '\n');
}
} while (error == 1);
for (int i = 0; i < 35; ++i)
{
oneColumn[i] = input;
twoColumn[i][1] = toLongRoman(input);
lowerOutput = twoColumn[i][1];
lowerOutputSecond = toLower(lowerOutput);
twoColumn[i][2] = lowerOutputSecond;
input = input + 1;
}
for (int c = 0; c < 20; ++c) {
cout << oneColumn[c] << " " << twoColumn[c][1] << " " <<
twoColumn[c][2] << endl;
}
}
string toLongRoman(int a) {
int b, stringPos = 0;
char romanString[100] = "0";
while (a >= 1000) {
b = a / 1000;
if (b >= 1) {
romanString[stringPos] = 'M';
stringPos++;
a = a - 1000;
}
else {
break;
}
}
while (a >= 500) {
b = a / 500;
if (b >= 1) {
romanString[stringPos] = 'D';
stringPos++;
a = a - 500;
}
else {
break;
}
}
while (a >= 100) {
b = a / 100;
if (b >= 1) {
romanString[stringPos] = 'C';
stringPos++;
a = a - 100;
}
else {
break;
}
}
while (a >= 50) {
b = a / 50;
if (b >= 1) {
romanString[stringPos] = 'L';
stringPos++;
a = a - 50;
}
else {
break;
}
}
while (a >= 10) {
b = a / 10;
if (b >= 1) {
romanString[stringPos] = 'X';
stringPos++;
a = a - 10;
}
else {
break;
}
}
while (a >= 5) {
b = a / 5;
if (b >= 1) {
romanString[stringPos] = 'V';
stringPos++;
a = a - 5;
}
else {
break;
}
}
while (a >= 1) {
b = a / 1;
if (b >= 1) {
romanString[stringPos] = 'I';
stringPos++;
a = a - 1;
}
else {
break;
}
}
return romanString;
}
string toLower(string s)
{
char result[50] = { 0 };
for (unsigned int i = 0; i < s.length(); i++)
{
s[i] = tolower(s[i]);
result[i] = s[i];
}
return result;
}