I'm having difficulty working with C++'s strings. I'm writing a program to solve a set of linear equations. I'd like to save the solution for various values of N (the size of the system is N X N), and n, a parameter within the system, to a text file, for later analysis. Ideally, I'd like to create a program that lets me enter a value for N (eg. 50 or 4000) and n (eg. -3 or -5) and then saves the solution to the system to a file called "50N_-3n.dat" or something.
1. How do I enter an int, and then make it a string? the following, stolen from the internet, does not do it:
string int_to_s(int num, string& converter){
toString << num;
converter = toString.str();
return converter;
}
This returns: myfirst.cpp: In function ‘int main()’:
myfirst.cpp:12: error: a function-definition is not allowed here before ‘{’ token
I've placed this function definition well below int main() {
2. Once I create a string with value "50", how do I glue it into an output file name?
string name;
name="myhouse_" en ".dat";
ofstream outfile;
outfile.open(name);
In this test code, en is supposed to be "50", and the file should be myhouse_50.dat. C++ says:
myfirst.cpp:28: error: expected `;' before ‘en’
myfirst.cpp:29: error: aggregate ‘std::ofstream outfile’ has incomplete type and cannot be defined
How do you get outfile.open to understand the VALUE of name?
As you can probably tell, I have very little experience with C++. Thanks,
Dave