I am reading from a file into a string until I reach a delimitting character, the dollar symbol. But the input iterator is skipping whitespace so the string created has no spaces. not what I want in this case. Is there any way to stop the skipping behaviour? and if so how?
Here is my test code.
#include <iostream>
#include <fstream>
#include <iterator>
#include <string>
// istream iterator is skipping whitespace. How do I get all chars?
void readTo(std::istream_iterator<char> iit,
std::string& replaced)
{
while(iit != std::istream_iterator<char>()) {
char ch = *iit++;
if(ch != '$')
replaced.push_back(ch);
else
break;
}
}
int main() {
std::ifstream strm("test.txt");
std::string s;
if(strm.good()) {
readTo(strm, s);
std::cout << s << std::endl;
}
return 0;
}