cin

Is it possible to use CIN and QT ???

within Qt is it possible to use cin?? I can use cout but cannot find anywhere where it shows how to use ciin within a Qt Console application many thanks, gda2004 ...

Using input to call a member function

Is it possible to use Input to call a member function? void one() { } cout << "enter input:" << endl; cin >> input; //where input is "one" instance.input() ...

First while loop's first iteration always fails to take input. 2+ loops work fine.

The bug starts at cin.getline ( string, 25, '\n' ); or the line below it (strtod). If I use cin, it works, except I cannot quit out. If I type anything that's not a double, an infinite loop runs. Need help. Basically, the first iteration runs, does not ask for input, so the user gets the math questions wrong. The second iteration works f...

cin erratic behaviour

i'm newby to C++. Small code as follows: int main(int argc, char* argv[]) { cout << "function main() .." << '\n'; char ch1; int int1; cin >> ch1; cin >> int1; cout << ch1 << '\n'; cout << int1 << '\n'; return 0; } when i run the program and input the following: function main() .. az i get : a 32767 i understand the 'a...

C++ cin questions

This seems to be weird: int main(int argc, char* argv[]) { cout << "function main() .." << '\n'; char ch = 0; double number_value=1.1; cin >> ch; cin.putback(ch); cin >> number_value; cout << "1 .. " << " " << cin.good() << " " << number_value << '\n'; cin >> number_value; cout...

C++ cin keeps skipping.....

I am having problems with my program. WHen I run it, it asks the user for the album, the title, but then it just exits the loop without asking for the price and the sale tax. Any ideas what's going on? This is a sample run Discounts effective for September 15, 2010 Classical 8% Country 4% International 17% Jazz 0% Rock 16% S...

C++ cin problems. not capturing input from user

I have the following method which is not capturing anything from the user.If I input New Band for the artist name, it only captures "New" and it lefts out "Band". If I use cin.getline() instead nothing is captured. Any ideas how to fix this? char* artist = new char [256]; char * getArtist() { cout << "Enter Artist of CD: " << endl;...

Problem of using cin twice.

Here is the code: string str; cin>>str; cout<<"first input:"<<str<<endl; getline(cin, str); cout<<"line input:"<<str<<endl; The result is that getline never pauses for user input, therefore the second output is always empty. After spending some time on it, I realized after the first call "cin>>str", it seems '\n' is still stored in ci...

C++ CIN cin skips randomly

I have this program, but cin in randomly skips.. I mean sometimes it does, and sometimes it doesn't. Any ideas how to fix this? int main(){ /** get course name, number of students, and assignment name **/ string course_name; int numb_students; string assignment_name; Assignment* assignment;...

User input... How to check for ENTER key

I have a section of code where the user enters input from the keyboard. I want to do something when ENTER is pressed. I am checking for '\n' but it's not working. How do you check if the user pressed the ENTER key? if( shuffle == false ){ int i=0; string line; while( i<20){ cout << "Playing: "; songs[i]->prin...

C++ cin whitespace question

Programming novice here. I'm trying to allow a user to enter their name, firstName middleName lastName on one line in the console (ex. "John Jane Doe"). I want to make the middleName optional. So if the user enters "John Doe" it only saves the first and last name strings. If the user enters "John Jane Doe" it will save all three. I was ...

How to cin Space in c++?

Say we have a code: int main() { char a[10]; for(int i = 0; i < 10; i++) { cin>>a[i]; if(a[i] == ' ') cout<<"It is a space!!!"<<endl; } return 0; } How to cin a Space symbol from standard input? If you write space, program ignores! :( Is there any combination of symbols (e.g. '\s' or something li...

program crashes at CIN input | C++

hello okay, so i made a DOS program however my game always crashes on my second time running to the cin function. #include <iostream> #include <string> #include <ctime> #include <cstdlib> using namespace std; //call functions int create_enemyHP (int a); int create_enemyAtk (int a); int find_Enemy(int a); int create_enemyDef (int a); ...

How do you make cin typesafe?

It is well known that cin is not typesafe (e.g. cin >> integer; and entering "fifty five" will cause it to flip out). I have seen many not-so-elegant ways to hand this, such as getlining a string and using sstream to convert it to a number, or looping with cin.fail() and clearing the stream and reentering it, etc. Is there any library or...

A question about cin in C++

Hello. When I declare int weight and then input a double value 165.1 a 2nd cin >> height; doesn't work and there is no any error message. Can you tell me why? VS2010 Console Application used. #include <iostream> using namespace std; const double lbs_to_kg = 2.2046, inches_to_meter = 39.370; int main() { int weight, height; ...

Simple noob I/O question (C++)

Hi, sorry for the noob question, but I'm new to C++. I need to read some information, line-by-line, from a file, and perform some calculations, and output into another file. For example, we read a unique ID for each line, a name, and 2 numbers. The last 2 numbers are multiplied, and in the output file, the ID, name and product are print...

how do I check if input from cin is a double?

Possible Duplicates: How to validate numeric input C++ how do I validate user input as a double in C++? I need to get input from the command line and check if it is a valid number... storing it as a double. If the input is invalid, I need to keep asking for a number. double x; cout << '>'; cin >> x; while (/*x is invalid*...

how do I validate user input as a double in C++?

How would I check if the input is really a double? double x; while (1) { cout << '>'; if (cin >> x) { // valid number break; } else { // not a valid number cout << "Invalid Input! Please input a numerical value." << endl; } } //do other stuff... The above code infinitely outputs the Inv...

Find the end of stream for cin & ifstream?

Hi, I'm running myself through a C++ text book that I have as a refresher to C++ programming. One of the practice problems (without going into too much detail) wants me to define a function that can be passed ifstream or cin (e.g. istream) as an argument. From there, I have to read through the stream. Trouble is, I can't figure out a wa...

cin and buffer problem

Hi I have question regarding cin and buffer. I want to make a simple io program which takes integers. Anyway I stumbled to a problem with buffer. Using MinGW in windows7 the following code will print out all four integers that I input. But when I switch to SunOS and compile it with G++ it will only print out the first integer. Is this a...