Hey there,
I'm new to this forum, so first of all hi to everyone :P.
Lately, I encountered some problem which I don't know how to solve it. This weird behaviour has to do with reading a line in a text file. I have the code below.
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char *argv[])
{
std::ifstream file;
string filename = "halloo.txt";
string input;
file.open((filename).c_str());
if(!file.is_open())
{
cout << "ERROR: FILE IS NOT OPEN" << endl;
}
while(1)
{
if(file.eof())break;
getline(file, input);
//cout << input << endl;
for(int i=0; i<input.size(); i++)
{
if(isalnum(input))
{
cout << input << " is woord" << endl;
}
else
{
cout << input << " is symbol" << endl;
}
}
//cout << input << endl;
}
system("PAUSE");
return 0;
}
What i want to do is read a line from the text file and print it on a console. My text file is very simple. It consist one letter 'd' and a new line (pressed enter).
I'm working with dev c++ and this works comepletely fine.
When I read this it print's:
"d is a woord".
But when I run this on an UNIX system it gives me a completely different prints.
it prints:
" is woord" (with an empty space before "is")
" is symbol" (with an empty space before "is")
This is where I find it difficult to understand. It does not do what I want. It gives me a different print than dev c++.
Does anyone know this problem and can help me about it ?