#include <vector>
#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
#define Rows = 4
#define Cols = 3
int main()
{
fstream infile;
infile.open("numbers.txt");
int Matrix[Rows][Cols];
//Input
for (int i = 0; i < Cols; i++)
for (int j = 0; j < Rows; j++)
infile >> Matrix[j][i];
//Output
for (int i = 0; i < Cols; i++)
{
for (int j = 0; j < Rows; j++)
std::cout << Matrix[j][i] << "\t";
std::cout << "\n";
}
return 0;
}
today when i tried to run it to print and turn into a class, it had compile errors in the underlined areas.
it would be greatly appreciated if some one could tell me why the error is occurring or an alternative but similar way i could display it in the same fashion.
if you know the reasoning behind the error, would you mind explaining it?
I realize where the issue is occurring.
You're not helping me with homework as I've already turned it in with mistakes. When I run the last successful build, it still works so i am really confused as to what happened.
#define takes everything after the name given and places that whereever it finds the name in your code. So with the way you did it before, this is what your code would have looked like to the compiler:
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
int main()
{
fstream infile;
infile.open("numbers.txt");
int Matrix[= 4][= 3];
//Input
for (int i = 0; i <= 3; i++)
for (int j = 0; j <= 4; j++)
infile >> Matrix[j][i];
...
return 0;
}