I have a program that reads 3 strings from a text file and outputs them as three columns. I am using MS Visual Studio 2022 for this. Upon running the program, the output I expected is shown, but so is an error message that states "Debug Error! Program:(file location) abort() has been called".
using namespace std;
int main() {
string str1, str2, str3;
ifstream inFile;
inFile.open("strings.txt");
getline(inFile, str1, '\n');
getline(inFile, str2, '\n');
getline(inFile, str3, '\n');
if (str1.length() >= str2.length() && str1.length() >= str3.length()) {
for (int i = 0; i <= str1.length(); i++) {
cout << str1.at(i) << " " << str2.at(i) << " " << str3.at(i) << endl;
}
}
if (str2.length() >= str1.length() && str2.length() >= str3.length()) {
for (int i = 0; i <= str2.length(); i++) {
cout << str1.at(i) << " " << str2.at(i) << " " << str3.at(i) << endl;
}
}
if (str3.length() >= str1.length() && str3.length() >= str2.length()) {
for (int i = 0; i <= str3.length(); i++) {
cout << str1.at(i) << " " << str2.at(i) << " " << str3.at(i) << endl;
}
}
system("pause");
return 0;
}