I am trying to read a file in a buffer and then use the regex iterator. I know that I can use the C ++ line iterator with the regex iterator (constructor std::regex_iterator<std::string::iterator>), but I would like to avoid copying my buffer to the line and continue to use low-level functions to read the file (right now I'm using open()and read()).
struct stat buff;
int file = open(argv[1], O_RDONLY);
if(!file)
cout << "Error opening file" << endl;
else if(fstat(file, &buff))
cout << "Error" << endl;
else
{
cout << (buff.st_size) << endl;
char fr[buff.st_size+1];
read(file, fr, buff.st_size);
fr[buff.st_size] = '\0';
}
close(file);
I think my options are to find a way to use read()with a C ++ string instead of char * or a way to use the regex iterator in a char array. I could write one, but I also try to keep my program as small as possible.
Is there any way I can do this? How to use C ++ string as C char * (for read())?