#include <boost/regex.hpp>
#include <boost/algorithm/string/regex.hpp>
#include <iostream>
#include <fstream>
#include <string>
//#include <conio.h> //getch()
void parse_file (std::ifstream& file_in){
std::string buffer;//buffer to store lines of raw data
while (!file_in.eof()){
//read the raw data into the buffer
getline(file_in, buffer);
std::vector <std::string> fields;
split_regex( fields, buffer, boost::regex( "\aBCDEF " ) );
//print out the fields
for (size_t n = 0; n < fields.size(); n++){
std::cout << "\"" << fields[ n ] << "\"\n";
}
//std::cout << "\n\nPress any key to loop again\n\n";
//getch(); //commented out for now
file_in.close();
break;//testing
}//while loop bracket
}
I guess you need to include three backslashs then the special characters
so this now functions the way I wanted it too.
It is the three backslashs to keep it from being escaped and then the backslash for the character at least that's how I think it was working
I can understand three backslashes, (one for c++, one for regex, and one for the character) but the fourth I'm uncertain why?
Maybe it's escaped for regex then boost then c++ then the character?
I'm just making this up and I have no idea how it actually works but if anybody knows please set me straight. Either way, I now know I need three backslashes then the character so on to the next problem ;p
#include <iostream>
int main()
{
std::cout << "\\\\aBCDEF" << '\n' ; // C-style literal for regex \\aBCDEF
// each backslash needs to be escaped, we need two of them for the regex
// two \\ for the first escaped backslash, two \\ for the second escaped backslash
// adding up to four. "\\\\" is the C-style literal for two backslashes in succession
// in C++, we should prefer a raw string literal for constructs of this kind
// http://www.stroustrup.com/C++11FAQ.html#raw-strings
std::cout << R"(\\aBCDEF)" << '\n' ; // C++ raw string literal for regex \\aBCDEF
}