My input file is like this:
C:\Users\DeadCoder\AppData\Local\CoCreate
I am making a tree and I need to abstract the names of directories while reading from input file with \
delimiter. Like in the above example, i need to abstract separately c:, users, DeadCoder, Appdata .... I hope every one understands the questions.
Now Let us see the options that we got.
1-
istringstream
works perfectly fine for whitespace
but not for \
.
2-
strtok()
works on char. So I would have to change my string to char and I really don't want to do this.
3- Boost Tokenizer()
This one seems interesting and I don't have any familiarity with it in the past except I just googled it a while ago. I copied the code and it is like this:
#include <boost/foreach.hpp>
#include <boost/tokenizer.hpp>
using namespace boost;
int main(){
string tempStr;
ifstream fin;
fin.open("input.txt");
int i=0;
while (!fin.eof()){
getline(fin,tempStr);
char_separator<char> sep("\"); // error: missing terminating " character
tokenizer<char_separator<char>> tokens(tempStr, sep);
for (const auto& t : tokens) {
cout << t << "." << endl;
}
}
Now this gives the error that "error: boost/foreach.hpp: No such file or directory"
can Someone help me here. And Is there any other better way
to read the input file with \ delimiter
. Please don't use extensive codes like class tokenizer()
as I am still learning c++.
EDIT: I didn't have boost library installed therefore I was having this error. it would be much of favor if someone can explain a better way to tokenize
string without installing a third library.
Best; DeadCoder.