cin

C++ common interface for "cin" and "File"

Is there a common interface for cin and file input? I want to make a program that has an optional parameter prog [input-file] If an input file is specified, then it should read from the file, and if not, it should read from cin. From what I can tell, they both implement istream. How would you set up it so that I could do something l...

cin.getline is skipping one line of input and taking the next

Why does cin.getline start working for the second line on the body input but break on the first? Example Program run: Enter name: Will Enter body: hello world hello again <= It accepts this one char* name = new char[100]; char* body = new char[500]; std::cout << "Enter name: "; std::cin.clear(); std::cin.ignore(std::numeric_l...

Loop problem. Cin C++ getline clear buffer

I am having a problem, but I cannot figure out what I'm doing wrong. I'm not sure if it's a problem with my loop, or the cin buffer is not being cleaned. I am doing a program that transforms a C-style string to uppercase, however if the user enters more than 11 characters, then the function should only display the first 11, and anything ...