cin Questions
23
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...
6
Solved
When should std::cin.getline() be used? What does it differ from std::cin?
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)...
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...
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 ...
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;...
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...
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...
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...
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...
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)...
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...
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...
3
Solved
What does cin.ignore(numeric_limits<streamsize>::max(), '\n') mean in C++?
Does it actually ignore the last input from the user?
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...
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...
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 >>...
Ovotestis asked 22/7, 2011 at 14:29
1 Next >
© 2022 - 2025 — McMap. All rights reserved.