Im currently making a programming that reads a text file, performs calculations, and then returns the results to a new text file. So far the program return the basic details of the text file, however, Im struggling in parsing the results of two functions that perform calculations, to a writetoFile function(that, as the name sugguests, writes all the output to a new text file).
This is the 2 calcualation fuctions, as well as the writetoFile function
//function 1
double robotComplexity(std::vector<std::string>& lines) { //takes in the out.txt file
std::string output = lines[0]; //so far only reads the first line of the output file.
std::string input = output.substr(18,1);
double complexity = 20 * atoi(input.c_str());
if(complexity > 100) {
complexity = 100;
}
cout << "The Robot Complexity is: " << complexity << endl;
return complexity;
}
//function 2
double robotVariability(std::vector<std::string>& lines) {
std::string output = lines[0]; //so far only reads the first line of the output file.
std::string input = output.substr(15,2);
double variability;
variability = 5 + atoi(input.c_str());
cout << "The Robot Variability is: " << variability << endl;
return variability;
}
//function to write to file.
void writeFile(std::string const& outputFile,
std::vector<std::string> const& lines, double unitComplexity, double unitVariability)
{
std::ofstream file(outputFile);
for(std::string const& line: lines)
{
file << line << std::endl;
}
}
I tried using an enchaned for loop of type double but it doesnt accept it, recieving the error, "this range-based 'for' statement requires a suitable "begin" function and none was found"
To reiterate, im trying to add the results of robotComplexity function and the robotValdity function to the output file shown in the writefile function. If any further code is required, please feel free to ask. Thankyou.
Aucun commentaire:
Enregistrer un commentaire