Hello sunshine4,
This covers some of what
Enoizat has said, but I will say it anyway.
I will start with the header files:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include "pch.h"
#include <cctype>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <cassert>
#include <fstream>
#include <algorithm>
//#include <Windows.h>
//#include <math.h>
//#include <cmath> // <--- Same as "math.h", but the C++ version.
//#include <sstream>
//#include <conio.h>
//#include <stdio.h> // <--- Covered under "iostream
//#include <sstream>
//#include <sstream>
//#include <iostream> // std::std::cout
//#include <string> // std::std::string
//#include <cstddef> // std::size_t <--- I have never needed this for "size_t". And you never use "size_t" in the program.
|
The first section is what I consider the header files that you are most likely to use in a program. At first I did not realize that they are in alphabetical order. Being this way it helps to remind you when you miss an include file. The second section I think of as the extra header files the the program needs. The third section, the ones commented out, are the duplicates or the header file that you do not need.
"Windows.h" is never used in this program.
"math.h" and "cmath" are the same thing. The "cmath" just puts "math.h" in the standard name space.
"sstream" is not used right now, but could be useful.
"stdio.h" The comment says it all.
"conio.h"
salem c wrote:
> #include<conio.h>
Obsolete since 1990, when the world stopped using DOS as a primary operating system.
|
Also not everyone has this header file available for use. Then there is the point that you never use anything from this header file.
I think I found the input file in another thread.If you are going to remove the new line characters then you file should look like:
1 seven three two eleven four nineteen two five seventeen one five
2 eight six twelve eleven thirteen twenty two fifteen fourteen sixteen ten
|
This way you could use
std::getline(inFile, line);
then use the string stream to extract the number into a numeric variable and then the words that you can put into your vector.
The function "setRow" is not working the way you are thinking.
values.resize(r + 1)
is working, but you are resizing the columbs of the second dimension not the rows.
What I ended up trying is to write the default ctor as:
1 2 3 4
|
ContainerQ() // <--- Default ctor.
{
values.resize(MAXROWS, std::vector<std::string>());
}
|
"MAXROWS" is defined above the class as
constexpr size_t MAXROWS{ 11 };
. You may think that the 11 is an odd number, but what it allows for is not using element (or row) zero. I started with a small number until the program is working. Later you can change the 11 to what you need.
Since the first "cout" statement says
[1 - 225]
you will need to make it 226.
I believe that resizing the vector in the ctor should eliminate the need for the "setRow" function.
I will do some more testing and see what else I can find.
Hope that helps,
Andy