Hello MADZILLA,
I have not worked out everything yet, but for a start:
You say that you can not use a "std::string", but you have included the header file "string". Why?
Your variable "name" is defined as a single "char" and I believe it should be an array. Second you are trying to initialize a single "char" with a string. This will not work. To be correct it should be single quotes around the (\0).
From C++11 on the use of empty {}s will properly initialize a variable. Or as you will see you can put something between the {}s.
Unless you need "i" and "j" outside of the for loops they should be defined in the for loops as:
for (int i = 0; i < 5; i++)
actually I would suggest
for (int i = 0; i < MAXROW; i++)
For line 16 a "std::getline(...)" is only used with a "std::string", which you can not use. I have not tested this yet, but I believe what you need is:
std::cin.getline(name, MAXSIZE);
Your use of ".empty()" is a member function of the "std::string" class and can not be used on a character array. It has been awhile, but I think you want the C function of "strlen()".
In your last else statement the "=" would work with a "std::string", but for a character array you would need to use "strcpy" for this.
I have realized that you are using VS2017, which compiles to a minimum of C++14 standards, 0so the C functions of "strlen()" and "strcpy" are likely to be a problem. The compiler should suggest an alternative or you can put
#pragma warning(disable : 4996)
after your include statements.
Since you entire program is in "main" you should use
return 0;
and not
exit(0);
I changed the beginning of the program. You should find this easier to work with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int main()
{
constexpr size_t MAXROW{ 5 };
constexpr size_t MAXCOL{ 10 };
constexpr size_t MAXSIZE{ 10 };
char StudentName[MAXROW][MAXCOL]{};
char name[MAXSIZE]{}; // <--- Changed.
//int i = 0, j = 0;
for (int i = 0; i < MAXROW; i++)
{
for (int j = 0; j < MAXCOL; j++)
{
|
Using VS2017 "size_t" should be a typedef for an "unsigned int" unless you have changed the "Solution Platform" from "x86" to "x64" then "size_t" is typedefed as a "long".
Until I can correct the problems I do not know yet how the program runs.
Hope that helps,
Andy