Sorry, noob question, have searched the forum and not found what I think I need...
Reading a text file and simply want to print the char value read from the file, character by character... I can print it as an int, but can't read it and print, or even cast, it to a char value... can print the dec or hex rep of the character, not the character... why is "next" an int?
#include <stdlib.h>
#include <fstream>
#include <cstring>
usingnamespace std;
int main() {
char next; // character from file
ifstream dataIn;
dataIn.open("data.txt");
if (dataIn.fail())
{
printf ("\nFailed to open data file\n\n");
exit(1);
}
while (! dataIn.eof())
{
dataIn.get(next);// read next char value ... why is it not a char???
if (next != '\n')
{
if (next != ' ')
{
printf ("%s ", next); // generates an error... not a char value
// printf ("%d ", next);
}
} // end if not \n
} // end of while not eof
dataIn.close(); // close file when done
}