I am having a problem with an error function which' purpose it is to check a variable and in a certain case tell me the variables name and its value.
I want to give the value as well as the name (as a string) to the function but I am having problems declaring a string somehow (Eclipse MinGW C++).
If anyone could point me to my mistake or show me a workaround that would be great!
This is the code:
#include <string>
#include <iostream>
using namespace std;
int *ierr;
std::string(varname); //problem here, doesnt recognize the string
void error(double varvalue, std::string varname)
{
if (varvalue == 0 ) {
*ierr = 11;
cout << "Error: " << varname << " has an invalid value (equal 0)";
cout << "Error number " << *ierr << endl;
return;
}
if (varvalue < 0 ) {
*ierr = 10;
cout << "Error: " << varname << " has an invalid value (" << varvalue << " , smaller 0)";
cout << "Error number: " << *ierr << endl;
return;
}
}
int main() {
int Par = 0;
error(Par,"Par"); //test variable
}