Here is my code:
#include<iostream>
#include<string>
#include<cstring>
#include<string>
#include<fstream>
#include<vector>
#include"input.h"
#include<cmath>
#include<wchar.h>
using namespace std;
void Challenge1(vector<string>& vData);
int main(vector<string>& vData)
{
do
{
system("cls");
switch (toupper(inputChar("ntSelect an option: ", "ABCX")))
{
case 'X': exit(1); break;
case 'A': Challenge1(vData); break;
//case 'B': Challenge3(); break;
//case 'C': Challenge6(); break;
default: cout << "ttERROR - Invalid option."; break;
}
cout << "n";
system("pause");
} while (true);
}
void Challenge1(vector<string>& vData)
{
ifstream inputFile;
string filename = inputString("ntEnter a data file (Triangles.TXT): ", true);
inputFile.open(filename);
if (inputFile.fail())
{
cout << "ntERROR: " << filename << " cannot be found.n";
return;
}
vData.clear();
string value;
while (inputFile >> value)
{
vData.push_back(value);
}
inputFile.close();
cout << "ntCompleted reading data from file and stored into array.n";
}
I’m trying to read a text file (has number) and store it in a vector so I can display it later in the option menu (Case B). But it crash whenever I tried to run (store) the text file.
I still have a lot to learn, any help is much appreciated.
New contributor
Nubi is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.