I am currently trying to read some words from .txt document and manage to read and display only letters Can do so far I also want to do this, but with full words
My code:
#include & lt; Iostream & gt; # Include & lt; Fstream & gt; #include & lt; String & gt; using namespace std; Int main () {ifstream infile ("banned.txt"); If (! Infail) {cout & lt; & Lt; "Error:"; Cout & lt; & Lt; "Can not open input file \ n"; } Infile & gt; & Gt; Noskipws; While (Infile.eof ()) {char ch; Infile & gt; & Gt; Ch; // It is useful to see that the read file // is not the end - it closes the output of an extra character at the end of the loop if (! Infile.eof ()) {cout & lt; & Lt; F & lt; & Lt; Endl; }} System ("pause"); }
change four letters,
to std :: string word;
and infile & gt; & Gt; Ch;
to infile> & Gt; word;
And you're doing or loop better than this:
std :: string term; While (infile> word;) {cout & lt; & Lt; The word & lt; & Lt; Endl; }
No comments:
Post a Comment