Questions tagged [cin]

std::cin is the global stream object provided by the C++ standard library for reading from the standard input stream.

For more general questions about std::istream use the or tags.

1859 questions
0
votes
1 answer

c++ issues with cin.fail() in my program

I want to use input y to do saving thing,and r to do resuming, but then i write it in the following codes,and then I input y or r,I just to be noticed ""Please enter two positve numbers" this line code "if(x==(int)('y'))"and next line is ignored.how…
Wallace
  • 151
  • 1
  • 9
0
votes
3 answers

why is my compiler complaining when i try to clear the cin buffer

i am writing a program where i am trying to implement the following code: int main(){ string inputcmd; while (getline(cin, inputcmd)){ cout << "TYPE A COMMAND" << endl; cin >> inputcmd; cin.ignore…
notamathwiz
  • 225
  • 1
  • 5
  • 14
0
votes
3 answers

Creating a multiple class instances from user input

I was wondering if it was possible to create multiple class instances solely from a user input. For example: Class Person{ int a; int b; } Person 1; Person 2; etc... int number; Then cout << "Ask user to input a number for amount of…
0
votes
1 answer

when i call my function the while loop skips a step

this is my code: string getFileContents(istream& file_contents){ string line; getline(file_contents, line); return line; } project read_project(istream& in){ project newproject; while(cin){ cout << "Enter your project name:…
notamathwiz
  • 225
  • 1
  • 5
  • 14
0
votes
3 answers

Stack around the variable is corrupted

I have what seems like a pretty simple, beginner question that I must be missing something obvious. I am just trying to prompt the user to input a 4 digit number and then take in the input as an array, splitting up the digits to be by themselves. I…
0
votes
3 answers

Splitting a String in C++ (using cin)

I'm doing THIS UVa problem, which takes in the following input: This is fun- ny! Mr.P and I've never seen this ice-cream flavour before.Crazy eh? # This is fun- ny! Mr.P and I've never seen this ice-cream flavour before.Crazy eh? # and produces…
muttley91
  • 12,278
  • 33
  • 106
  • 160
0
votes
4 answers

program crashes when attempting to set the value of a string issue with cin >>

This is a bizarre error that I have never seen before, and do not know how to fix it. The crash occurs on na = m Here is the relevant code. The line in question is marked with *: In Main: #include #include #include…
0
votes
2 answers

How does `cin>>` take three values though they are separated by space?

When looking at some code online I found cin>>arr[0][0]>>arr[0][1]>>arr[0][2] where I put a line of three integer values separated by space. I see that those three integers separated by space become the value of arr[0][0], arr[0][1] and…
Anklon
  • 618
  • 2
  • 8
  • 21
0
votes
1 answer

Pipe a file of bytes to C++program, via Linux and read byte-by-byte?

Is there a way to pipe a file of (bytes- obviously) in to a C++ application on Linux. However, rather than just use getline() I would like to read each byte only once. For example I don't want to use getline() because it would read all the bytes up…
user997112
  • 29,025
  • 43
  • 182
  • 361
0
votes
2 answers

How to read symbols until ESC button is pressed from cin in C++

I need to make my while loop works until ESC button on keyboard is pressed. char choose = NULL; while( choose != 27) { cout << "Choose (s), (e) or (n): "; cin.ignore(); choose = cin.get(); switch(choose){ case 's':…
Heidel
  • 3,174
  • 16
  • 52
  • 84
0
votes
2 answers

Issue with cin.peek() and having issues getting correct input

ok so eventually im going to be making a postfix calculator with a stack implementation and getting inputs such as 45 20+. I'm just having trouble with getting the input correct, I want to ignore whitespace, if the user enter a number, i want to cin…
user1940516
  • 41
  • 1
  • 3
  • 6
0
votes
1 answer

Trouble using cin.peek() and detecting end of input with cin.peek()

1 #include 2 using namespace std; 3 4 #include"dstack.h" 5 6 int main() 7 { 8 char value = cin.peek(); 9 char op; 10 double num; 11 12 while(value != cin.eof()) 13 { 14 if( (isdigit(value) || value == '.') ) 15 { 16 …
user1940516
  • 41
  • 1
  • 3
  • 6
0
votes
1 answer

Overloading operator>>

I have a Date class which I am trying to test with a simple program to ask the user to input a date in a certain format which will then be put into the class. The idea is to allow the user to set a Date class from any string of text starting with…
KG6ZVP
  • 3,610
  • 4
  • 26
  • 45
0
votes
2 answers

create class via input from cin fetched with operator>>

My assignment I to create the following classes with the following data members / member functions. Computer RAM (in GB). Processor Speed (in GHz). # of Cores Hard Drive Storage Size (in GB). Print (Virtual Function) Desktop (inherits from…
Josamoda
  • 77
  • 1
  • 13
0
votes
2 answers

Keep a running C++ program console on top?

Let's say I was using cin in my program to allow the user to input into the console. That is simple enough but what if they were typing into, let's say, a web browser and I wanted them to input that into the console at the same time? When I click…
aanrv
  • 2,159
  • 5
  • 25
  • 37
1 2 3
99
100