Okay, I've spent several hours looking and trying to figure out a way to extract whitespaces from a .txt file. I'm not sure if I'm explaining this correctly or not so far, so I'll give an example.
My .txt file reads like this
This is really awesome!
Yep, this came from a tutorail on gamedev. When I take in "This is really awesome!" into my program and display it I want all of it to display...not just "This". For some reason what I'm doing (using getline() ) isn't displaying anything at all when I cout that line. Well, here is my code, and if anybody could tell me what I'm doing wrong that would be great. I'm sure it isn't nearly as hard as I'm making it out to be, but I can't figure it out for some reason.
Btw, I'm using DevC++ 5beta18.104.22.168, and it being in beta is not the reason for it not working because it doesn't work with DevC++4.01 either.
#include <fstream.h> //used for
//lets represent the file as fin "file in"
ifstream fin("E:\\Documents and Settings\\Administrator\\Desktop\\bla\\test.txt");
//where the text file is located at ^
int number; // first line in .txt
float real; // second line in .txt
char letter, word; //third and fourth line in .txt
char sentence; //fourth line in .txt
// ^ this is the line of "this is totally awesome!"
fin >> number >> word >> real >> letter; //to receive all of the files
// ^ this part works fine when displaying
fin.getline(sentence, 100); //get up to 100 characters from the file
/*that should include the whitespaces too
instead nothing is displayed at all when trying to cout */ sentence
/*if i use "fin >> sentence" like the rest
it only displays "this" when COUTed
which should be the case when using fin (cin)
i've tried a few other things but none of them seem to work for me */
cout << number << endl; // displays fine
cout << word << endl; // displays fine
cout << real << endl; // displays fine
cout << letter << endl; // displays fine
cout << sentence << endl; // displays fine
getch(); // waits for user to hit "any key" then terminates program