I am reading the characters in one by one from a .txt file in order to manipulate them individually. I've found a way to preserve the punctuation/numbers, but I don't know how to preserve the whitespaces.
I know that >> ignores the white spaces by default. What can I do?
// istream::get example
#include <iostream> // std::cin, std::cout
#include <fstream> // std::ifstream
int main () {
char str[256];
std::cout << "Enter the name of an existing text file: ";
std::cin.get (str,256); // get c-string
std::ifstream is(str); // open file ("is" is an instance of type ifstream)
while (is.good()) // "good()" is a Boolean member function. you can checkout the reference for std::ios::good() on this website.
{
char c = is.get(); // get character from file
if (is.good())
std::cout << c;
}
is.close(); // close file
return 0;
}