In the following code I got somehow the following error (C++11,g+) :
template < typename T >static void write_csv(vector<pair< string, vector<T> > > dataset){
ofstream myFile("Results");
for(int j = 0; j < dataset.size(); ++j){
myFile << dataset.at(j).first;
if(j != dataset.size() - 1) myFile << ","; // No comma at end of line
}
myFile << "
";
}
The error is
error: no match for 'operator<<' (operand types are 'std::ofstream {aka ?std::basic_ofstream<char>}' and 'const char[2]
. ?
Also, I am attaching my includes for the program.
#include <math.h>
#include <vector>
#include <map>
#include <limits>
#include <climits>
#include <algorithm> // for std::sort
#include <string.h> // for memset
#include <stdio.h> // for printf
#include <assert.h>
#include <time.h>
#include <iostream>
#include <ostream>
#include <stdlib.h>
#include <random>
#include <cmath>
#include <gsl/gsl_math.h>
#include <gsl/gsl_cdf.h>
#include <gsl/gsl_randist.h>
using namespace std;
What can be the problem?
question from:
https://stackoverflow.com/questions/65872064/strange-error-in-c-operation-in-ofstream-cant-work-with-strings 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…