c++ - Reading whitespace from char -
i writing program practice need read text file , convert lowercase.
ifstream file("words.txt"); char c; while(file >> c) { if(isupper(c)) c = tolower(c); cout << c; }
this program simple enough, if want print file contents using same loop skip spaces.
while(getline(file, str)) { cout << str << endl; }
if made string str
, did while loop read file contents not print anything. ideal goal able read file, convert each char lowercase, , print text spaces included, preferably without repeating loops , writing lots of un-necessary code.
Comments
Post a Comment