apprenticecoder
apprenticecoder

Reputation: 11

C++ error loading .txt file using ifstream

I am trying to load in a text file that contains 1400 rows and 7 columns of data. The data consists of 15 point decimal numbers that have been pasted in to notepad via an excel spread sheet. Each element has a single space between them however this space displays as a tab once pasted from excel. The text file is located directly under my project file in the same directory.

I am using ifstream to load in the text file to then save each data element to an array however the text file consistently fails to open according to my code.

//define input stream
ifstream TrainData;     // 70% training data
TrainData.open("training_dataset_full.txt");
if (TrainData.is_open())
{
   cout << "File successfully open";
}
else
{
   cout << "Error opening file";
}

This consistently outputs Error opening file. Is there something obvious that I am missing?

NOTE: this is where all my text files are located...

File arrangement

Upvotes: 1

Views: 126

Answers (1)

EYakoumi
EYakoumi

Reputation: 429

instead of putting the file in the project folder put it in the debug / release folder. as the executable will look into the folder where it is and not the source code

Upvotes: 1

Related Questions