enter image description here

I have 2 questions: 1 - how to count the whole line? 2 - how to count only the third line? The first variable of type int remaining std::string . From the screenshot it can be seen that the reading takes place according to the words and the separator of the variables is a space.

Program Code:

 #include <windows.h> // кириллица #include <iostream.h> // ввод-вывод #include <cstdlib> // конвертация #include <string> // строка #include <fstream> // чтение-запись int unp_consignee; // унп грузополучателя std::string consignee; // грузополучатель std::string the_goods_to_delivery_have_accepted; // товар к доставке принял std::string by_proxy; // по доверенности std::string give_out; // выданной std::string the_consignee_has_accepted; // принял грузополучатель if (settings_txt_reading.is_open()) { settings_txt_reading >> unp_consignee; settings_txt_reading >> consignee; settings_txt_reading >> the_goods_to_delivery_have_accepted; settings_txt_reading >> by_proxy; settings_txt_reading >> give_out; settings_txt_reading >> the_consignee_has_accepted; } 

Text file data:

 20 dfgdf dfgdfg dfgdfg dfg3 dfgdf344 44 sdfsd55 66 66 67 
  • 3
    Add code and data as text to the question. In its current form, it is likely to close. - αλεχολυτ
  • std::getline ( settings_txt_reading, consignee); - vp_arth

1 answer 1

Reading from the input stream (for example, the console or file) through the operator >> provides reading up to the first character of the space group (space, newline, tab).

If you want to read the whole string with spaces, you can use the function std::getline . In your case it will be something like this:

 std::getline(settings_txt_reading, consignee); 

To read the third line, you must first read the first two, ignore them, and then read the desired one. Immediately take the third will not work, because you need to somehow determine where this line begins. If the lines were of fixed length, then you could use seekg for positioning on a specific byte.