Here's my function:
the string this function returns is empty, and buffer returns 0 as it's width
Code:
const char* getToken(std::ifstream& input) {
std::stringstream buffer;
char curChar;
bool inString = false;
//Get rid of any leading whitespace
while (input.peek() == ' ') {
input >> curChar;
}
//Extract the token
while (true) {
input >> curChar;
if (!inString && ( curChar == ' ' || curChar == '\n' || input.eof() == true )) {
break;
}
else if (curChar == '"') {
inString = !inString;
}
buffer << curChar;
}
char* toReturn = new char[buffer.width() + 1];
buffer.seekg(0,std::ios::beg);
for (int i{}; i<buffer.width(); ++i) {
buffer >> toReturn[i];
}
toReturn[buffer.width()] = '\0';
return toReturn;
}







