Home >Backend Development >C#.Net Tutorial >Compilation errors and solutions for the c++ minicsv library
There is a project that requires writing csv files to present data. There is a lightweight reading and writing library for csv called minicsv on Github, so I downloaded it. However, the following problems occurred when compiling example:
In file included from example.cpp:1:0:
minicsv.hpp: In function
'csv::ofstream& operator<<(csv::ofstream&, const
T&)':
minicsv.hpp:326:38: error: no matching function for call to
'csv::ofstream::escape_and_output(std::basic_ostringstream
ostm.escape_and_output(os_temp.str());
^
minicsv.hpp:326:38:
note: candidate is:
minicsv.hpp:266:8: note: void
csv::ofstream::escape_and_output(std::string&)
void
escape_and_output(std::string & src)
...
There are many errors, so I won’t post them anymore and take up space. These errors all come from the same function header. The function header is defined like this:
void escape_and_output(std::string & src)
And when calling, it looks like this:
ostm.escape_and_output(os_temp.str());
Obviously, the function header when calling requires an rvalue reference, and the real function header gives lvalue reference, the two do not match, so the compiler reports an error. The modification is very simple, just change "&" to "&", that is, change the function header to look like this:
void escape_and_output(std::string &
src)
The error is very obvious. I didn’t want to write it down at first, but I was afraid that people who are not familiar with c++0x would be at a loss, so I posted it. Also, I don't know why there is such an obvious error in the project - maybe the boss's compiler is too smart.
For more related articles, please pay attention to the PHP Chinese website (www.php.cn)!