I am writing a program, it is necessary to read information from a txt file and write information to the structure
struct disp_res{ int x; int y; }; struct NOTEBOOK{ disp_res size_display; int regeneration_frequency; float diagonal; float size_hdd; float price; char model; }; wrote the following code for this:
int main() { SetConsoleOutputCP(CP_UTF8); string name_file="C:\\Users\\Home\\Desktop\\AlgoritmAndStructData\\Lab1\\Lab1\\note.txt"; int strInFile; string buffer; nach: ifstream file(name_file); if (file.is_open()){ strInFile = getQuantityString(file); NOTEBOOK* array = new NOTEBOOK[strInFile]; int i = 0; file.close(); ifstream file1(name_file); while(!file1.eof()){ getline(file1, buffer); array[i].size_display.x=stoi(split(buffer)); array[i].size_display.y=stoi(split(buffer)); array[i].regeneration_frequency=stoi(split(buffer)); array[i].diagonal=stof(split(buffer)); array[i].size_hdd=stof(split(buffer)); array[i].price=stof(split(buffer)); array[i].model=strToChar(split(buffer)); i++; } outputFile(array, strInFile); } else{ if(dialog()) goto nach; } return 0; } the split method divides a line by a tab
string split(string str){ string delimiter ="\t", pos_string; int position_delimiter = 0; position_delimiter = str.find(delimiter); if (position_delimiter==-1) return str; else{ pos_string = str.substr(0, position_delimiter); str.erase(0, position_delimiter + delimiter.length()); return pos_string; } } getQuantityString method counts the number of lines in a file
int getQuantityString(ifstream &files){ int quantity = 0; string buffer =""; while (!files.eof()){ getline(files, buffer); quantity++; } return quantity; } gives an error when trying to convert a string to an int string in the main method
array[i].size_display.x=stoi(split(buffer)); The contents of the note.txt file
UTF-8 file encoding. What am I doing wrong, why does the stoi() method not work? Debugging looked reading is normal ... well, or so it seems to me
Split method works correctly 

while(!file1.eof()){- this is not done ... See ru.stackoverflow.com/questions/833980/… - Harrygoto nach;reinitializesfileresulting in undefined behavior. The situation when the string in thesplitempty is not processed. - VTT