I read a text file and found that it would not print spaces between words. I want to read each character character at a time, and then print the character in the output window. Reading will read the file, but does not display spaces, and I could not figure out why spaces are skipped.
Question: Why is my reading not reading empty characters in the test file?
When I find a blank character, I want to print the word Blank Space.
code:
#include "stdafx.h" #include "iostream" #include<iostream> #include<fstream> void readTestFile() { char ch; std::fstream fin("C:/Users/itpr13266/Desktop/myTest.txt", std::fstream::in); while (fin >> ch) { std::cout << "Letter: " << ch << std::endl; if (ch == ' ') <-- should catch a blank spaces { std::cout << "Blank Space" << std::endl; } else <-- Just write the letter { std::cout << ch << std::endl; } } } int _tmain(int argc, _TCHAR* argv[]) { readTestFile(); getchar(); return 0; }
Test file:
This is testing for fprintf... This is testing for fputs...
Output
Letter: T T Letter: h h ...etc...
user3376708
source share