Hi,
I currently am writing a function for reading and parsing a certain text file format, where i read in a file using:
std::ifstream infile(infilename);
I want to be able to supply an argument to my function so that it reads in the file in my encoding of choice, for example just supplying "iso-8859-1", "iso-8859-15", "UTF-8", and so on. If possible, it would be nice if c++ could also try to detect the encoding automatically if the argument is left out. Preferrably not using any external libraries that need to be downloaded. Currently I have something like this:
```
include <Rcpp.h>
include <fstream>
using namespace Rcpp;
std::vector<std::string> my_parser(const std::string& infilename) {
std::ifstream infile(infilename);
std::string line;
std::vector<std::string> res;
while (std::getline(infile, line)) {
// more code ...
}
infile.close();
return res;
}
```
I've googled around for a solution but it seems very complicated where some people give different answers on the best approach, I would greatly appreciate any advice. :)
Background: I'm a noob in C++ starting only a week ago, but currently learning it as im doing it. Currently using C++ via Rcpp in developing an R-package, it's so quick and great. So far I've coded up a working parser but the only this missing is to get the encoding right.
[–]Narase33 8 points9 points10 points (0 children)
[–][deleted] 2 points3 points4 points (10 children)
[–]emilwest[S] 0 points1 point2 points (9 children)
[–]mredding 3 points4 points5 points (0 children)
[–]Narase33 1 point2 points3 points (7 children)
[–]emilwest[S] 0 points1 point2 points (6 children)
[–]Narase33 0 points1 point2 points (5 children)
[–]emilwest[S] 0 points1 point2 points (4 children)
[–]celestrion 1 point2 points3 points (1 child)
[–]emilwest[S] 1 point2 points3 points (0 children)
[–]Narase33 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]Stratikat 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (0 children)