a simple way to do achieve this is to process it line by line and then remove the comment as suggested by @Galik.
you can add a simple function which removes comment from the given line.
template <typename T>
std::string RemoveComment(std::string line, T&& c) {
const auto pos = line.find(c);
if (pos != std::string::npos) {
line = line.substr(0, pos);
}
return line;
}
while(getline(asmFile, label)){
label = RemoveComment(label,'/');
// Note: you might want to continue in case of empty string
if(lable.empty()) continue;
// do your magic
}
another method which I can think of is to use ignore.
eg. Input file
some text.
/ comment.
some other text.
code:
while(getline(asmFile, label, '/')){
// for given input label will contain "some text."
// and position indicator will point to next char after delim '/'.
/* process label */
// skip till end of line
asmFile.ignore(std::numeric_limits<std::streamsize>::max(), '
');
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…