Hey again! I am getting an error with which I am unfamiliar with. It says
hw1prob1.cpp: In function âint main()â:
hw1prob1.cpp:20: error: expected primary-expression before â]â token
hw1prob1.cpp:20: error: âmakeGen2dArrayâ was not declared in this scope
hw1prob1.cpp:32: error: no match for âoperator<<â in âoutFile << *((*(x + ((long unsigned int)(((long unsigned int)third) * 8ul)))) + ((long unsigned int)(((long unsigned int)fourth) * 4ul)))â
hw1prob1.cpp:34: error: no match for âoperator<<â in âoutFile << std::endlâ
In addition, it says no match for the operator << which does not make sense because it is being used by a ifstream.
The error occurs in the line that is green. I think it may be a problem with the way I am inputting the parameter but Im not sure. Ive tried different parameter values but nothing seems to work. Any links/tips would be helpful.Code:#include <iostream> #include <fstream> using namespace std; #include "hw1.h" int main() { int** x; int value; int numRows; ifstream inFile; inFile.open("matInp.txt"); numRows = inFile.get(); int rowSize [numRows]; for (int i = 0; i < numRows; i++) { inFile >> value; rowSize[i] = value; } makeGen2dArray(x, numRows, rowSize[]); for (int start = 0; start < numRows; start++) { for (int second = 0; second < rowSize[numRows]; second++) { inFile >> value; x[start][second] = value + 5; } } inFile.close(); ifstream outFile; outFile.open("matOut.txt"); for (int third = 0; third < numRows; third++) { for (int fourth = 0; fourth < rowSize[numRows]; fourth++) { outFile << x [third][fourth]*; } outFile << endl; } freeGen2dArray(x, numRows); return 0; } template <class T> void makeGen2dArray(T ** &x, int numberOfRows, int rowSize[]) { x = new T * [numberOfRows]; for (int i = 0; i < numberOfRows; i++) { x[i] = new T [rowSize[i]]; } } template <class T> void freeGen2dArray(T ** &x, int numberOfRows) { for (int i =0; i < numberOfRows; i++) { delete [] x[i]; delete [] x; x = NULL; } }



LinkBack URL
About LinkBacks



