Hello jusurb,
You should compile you program before posting it and try to fix everything you can before posting. Include any errors that you do not understand with your other questions.
When I tried to check your code I found that the class is missing four definitions that the "Automobilis.cpp" file is trying to access.
I figured out that you included all the member function definitions inside the constructor. Each definition of a member function needs to be separate and the default constructor just contains a set of empty braces as I showed you in my previous message.
Testing the program did not work because I do not know what is in the file "Studentas1.o". Include the file in a message if it is small or at least five entries for testing.
Without the file "Studentas1.o" the function
void Duomenys1(Automobilis A[], int &m)
did not work because the file did not open. You could add this code to check the file status:
1 2 3 4 5 6 7 8 9 10 11
|
if (fd.is_open())
{
std::cout << "\n File " << iFileName << " is open" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(2));
}
else
{
std::cout << "\n File " << iFileName << " did not open" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3));
exit(1);
}
|
"iFileName" is defined as
string iFileName{ "Studentas1.o" };
. It was easier to add that one line than change everything in the stock code I use. I only changed the "fd" in the first line to match your program. The second line of the if/else requires the header files "chrono" and "thread" to work. You may find that useful in the future. The
exit(1);
of the "else" is because there is no need to go any farther with the program. The "1" tells whoever called the program that there was a problem. Not always needed, but useful.
In the function
void Duomenys1(Automobilis A[], int &m)
lines 21 - 24 will be a problem. Line 21
fd >> m;
will input something into "m", but possibly leave a "\n" in the input buffer that the "getline" on line 24 will read from the buffer first and not the file.
1 2
|
fd >> m;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
|
A "cin >> something or inputFile >> something" followed by a "std::getline()" will need this to clear the input buffer before the "getline()". Line 2 requires the header file "limits" to work.
Hope that helps,
Andy