There is an error concerning lines 10-14. I had been using this code previously without errors. I'm not sure what I may have changed.

The error is "invertMatrix.cpp:14: error: invalid use of incomplete type ‘struct std::stringstream’
/usr/include/c++/4.2.1/iosfwd:83: error: declaration of ‘struct std::stringstream’
"

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

typedef vector<double> Vec; //Vector
typedef vector<Vec> Mat; //Matrix

template <typename T>
string to_string(T const& value) {
    stringstream sstr;
    sstr << value;
return sstr.str();
}

string record( Mat &x, short e, string operand, short f ){
	double b = x[e][f];
	if( operand=="div" ) x[e] = x[e]/b;
		else if( operand=="mult" ) x[e] = b*x[e];
		else if( operand=="add" ) x[e] = x[e]+b*x[f];
		else if( operand=="sub" ) x[e] = x[e]-b*x[f];
	else return "OPERAND ERROR";
	string rec = "STEP "; rec += to_string(e); rec += ' ';
	rec += operand; rec += ' '; rec += to_string(f);

	print( x );
return rec;
}


Mat invert( Mat x ){
	short n = min( x.size(), x[0].size() );
	string log;

	for( short c=0; c<n-1; ++c ){
		log += record( x, c, "div", c );
		for( short r=c+1; r<n; ++r ) log += record( x, r, "sub", c );
	}
	for( short c=n-1; c>=0; --c ){
		log += record( x, c, "div", c );
		for( short r=c-1; r>=0; --r ) log += record( x, r, "sub", c );
	}

	println( log );
return x;
}

int main(){
	Mat x = insertMatrix();
	print( invert(x) );
return 0;
}

Try #include <sstream>

>>There is an error concerning lines 10-14. I had been using this code previously without errors. I'm not sure what I may have changed.

IT previously worked because you probably never used that function, so the program didn't instantiate it. But since now you are using it, the compiler instantiates it, and when it does, it sees a weird name called stringstream that it hasn't seen before, because in that file there is no definition or includes that says to the compiler that the weird looking name is defined. So to solve you problem, as suggested, include sstream, and then the compiler will see that the weird looking name has indeed been defined.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.