   Problem with getline() in C++
  Alright, I'm sure this has probably been brought before, but I couldn't find any other threads about it.I'm trying to use getline() to , uh, get a line from a .txt file. Example code, to give an idea of how I'm going about doing this:char itemName[32];  ifstream loadGame;loadGame.open ("maxsave.txt");loadGame.getline(itemName, 32);player->getWeapon()->setName(itemName);loadGame.close();The setName() function:bool ENTITY::setName(char *newName){if (strlen(newName) == 0 || strlen(newName) > 32)return false;strcpy(name, newName);return true;}The first is a very stripped-down example, as you can probably guess. Now, the problem I'm having is this: the program compiles and runs without any errors, but when I try to output the weapon's name after I've used getline() to (supposedly) load it from a file, it prints a blank line.I'm pretty sure the problem lies in the way I'm using getline(), because I've tested the setName() function with different parameters and it seems to work just fine. Well, enough of my speculation. Any help would be appreciated.   
  The getline() function works fine. I took your code and made a mini player class to hold your setName() and everything worked according to plan. Maybe there is indeed a problem in the functions of the class you made. Or maybe the file you are reading from has no text in it, or it exceeds the limit you placed on it. Small things like that can slip your mind when you are working on a big project. Here's the code I came up with:#include <iostream.h>#include <string.h>#include <fstream.h>class player{ private:    char name[32]; public:   bool setName(char *);   bool output();};bool player::setName(char *newName){if (strlen(newName) == 0 || strlen(newName) > 32)return false;strcpy(name, newName);return true;}bool player::output(){cout<<name<<endl;}int main(){  player Player;  char itemName[32];    ifstream loadGame;  loadGame.open ("maxsave.txt");  loadGame.getline(itemName, 32);  Player.setName(itemName);  Player.output();  loadGame.close();  cin.ignore();  cin.get();  return 0;};  Just want to point out you have off-by-one error(s).  I don't think these have to do with yout problem, but always a good idea to fix potential crash bugs.If your itemName is a null terminated character thing, with 32 bytes, the null takes up a final byte.  strlen("hello") returns the number 5, which is the number of characters in the string, not including the null.  So 32 bytes can hold a string up to size 31.  Note, your getline parameter is right, it's the setName function that has the off-by-one.;  The global getline function works much better.#include <iostream>using std::cout;using std::endl;#include <string>using std::getline;using std::string;#include <fstream>using std::ifstream;int main(void){ifstream infile("lala.txt");string line;// while there are lines remaining in the filewhile(getline(infile, line)){// non-blank lineif("" != line)cout << line;// truncate to 31 chars maxif(31 < line.length())line = line.substr(0, 31);// const char* conversion of strlen 31, char array size 32cout << line.c_str();}return 0;};  Woohoo! It works! Thanks for the help, all of you guys. :D   