cin Questions

23

I'm trying to ask the user to enter numbers that will be pushed into a vector, then using a function call to count these numbers. why is this not working? I'm only able to count the first number. t...
Domitian asked 4/12, 2011 at 18:43

3

Solved

I am new to C++ and I was wondering how the function cin in case of a boolean data works. Let's say for instance : bool a; cin >> a; I understand that if I give 0 or 1, my data a will be eit...
Cumbersome asked 5/10, 2014 at 14:18

6

Solved

When should std::cin.getline() be used? What does it differ from std::cin?
Pennington asked 20/1, 2011 at 10:18

9

I am having trouble rounding a GPA double to 2 decimal places. (ex of a GPA needed to be rounded: 3.67924) I am currently using ceil to round up, but it currently outputs it as a whole number (368)...
Vulgus asked 19/9, 2014 at 2:9

3

Solved

I have a text file in the following format: info data1 data2 info data1 data2 data3 data4... The problem is: the count (and length) of the data may be very large and cause run-time problems when...
Judicative asked 10/12, 2013 at 18:23

4

Solved

Is there any good reason why: std::string input; std::getline(std::cin, input); the getline call won't wait for user input? Is the state of cin messed up somehow?
Cismontane asked 25/7, 2011 at 16:8

6

Solved

On OS X Leopard, I am using Qt Creator as an IDE to work with C++. cout works fine as output, however, there is no way to provide input to cin as if it were on a console, like Visual Studio does fo...
Heterogamy asked 28/9, 2009 at 0:47

5

I find myself often using variables that contain a very small range of numbers (typically from 1 to 10) and would like to minimize the amount of memory I use by using the char data type instead of ...
Venlo asked 22/4, 2013 at 6:53

3

Solved

I have looked to no avail, and I'm afraid that it might be such a simple question that nobody dares ask it. Can one input multiple things from standard input in one line? I mean this: float a, b;...
Jaela asked 15/9, 2011 at 2:46

5

when reading from std::cin even if I want to read only one char. It will wait for the user to insert any number of chars and hit Enter to continue ! I want to read char by char and do some instruc...
Supersensitive asked 25/2, 2014 at 23:3

3

How can I use googletest to test a function that relies on user input via std::cin? For the example below, I'm looking for whatever code would allow me to add "2\n" to the std::cin stream so that ...
Figurate asked 5/12, 2017 at 23:20

6

Solved

So I was trying to get valid integer input from cin, and used an answer to this question. It recommended: #include <Windows.h> // includes WinDef.h which defines min() max() #include <io...
Environmentalist asked 18/7, 2012 at 14:45

14

Solved

How do I clear the cin buffer in C++?
Perplex asked 2/11, 2008 at 17:31

5

Solved

I am new to programming, and I have some questions on get() and getline() functions in C++. My understanding for the two functions: The getline() function reads a whole line, and using the newlin...
Doucette asked 11/11, 2014 at 19:58

1

Code #include<iostream> int main() { int x; std::cout<<(std::cin>>x)<<"\n"; std::cin.clear(); std::cin.ignore(); if(std::cin>>x) { std::cout<&l...
Dine asked 19/8, 2021 at 14:19

8

Solved

I was typing this and it asks the user to input two integers which will then become variables. From there it will carry out simple operations. How do I get the computer to check if what is entere...
Munro asked 10/9, 2013 at 21:6

2

Solved

I compiled this code at home on my mac w/ xcode and there was no provblem. I compile it at school with g++ on linux and I get these errors: numeric_limits’ is not a member of std expected primary-...
Gobble asked 25/1, 2011 at 21:17

5

Solved

So I have a function that keeps skipping over the first getline and straight to the second one. I tried to clear the buffer but still no luck, what's going on? void getData(char* strA, char* strB)...
Narbonne asked 29/8, 2012 at 21:9

4

The program below shows a 'int' value being entered and being output at the same time. However, when I entered a character, it goes into an infinite loop displaying the previous 'int' value entered...
Gillie asked 17/7, 2012 at 13:29

11

Solved

I used "cin" to read words from input stream, which like int main( ){ string word; while (cin >> word){ //do sth on the input word } // perform some other operations } The code struc...
Atomic asked 19/3, 2011 at 4:41

3

Solved

What does cin.ignore(numeric_limits<streamsize>::max(), '\n') mean in C++? Does it actually ignore the last input from the user?
Tchad asked 29/7, 2014 at 16:18

8

Solved

#include <string> std::string input; std::cin >> input; The user wants to enter "Hello World". But cin fails at the space between the two words. How can I make cin take in the whole ...
Nannette asked 30/4, 2011 at 0:48

9

I'm writing a program that prompts the user for: Size of array Values to be put into the array First part is fine, I create a dynamically allocated array (required) and make it the size the use...
Engorge asked 17/2, 2014 at 19:20

7

Solved

I wrote a very basic program in C++ which asked the user to input a number and then a string. To my surprise, when running the program it never stopped to ask for the string. It just skipped over i...
Polysyllable asked 24/8, 2014 at 19:17

9

I have been using "Accelerated C++" to learn C++ over the summer, and there's a concept which I don't seem to understand properly. Why is int x; if (cin >> x){} equivalent to cin >&gt...
Ovotestis asked 22/7, 2011 at 14:29

© 2022 - 2025 — McMap. All rights reserved.