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
2 answers

Reading a file where middle name is optional

I'm trying to read in a file formatted as firstName middleName(optional) lastName petName\n With the middle name being there on half the entries, I'm unsure as to the best way to read these in and get them into the correct variable names. Any…
Tyler Siegrist
  • 139
  • 4
  • 10
0
votes
2 answers

cin.getline() not working as desired

Iam tring to make a simple program that stores cricketers information onto a file and fetches it back but i have problems with cin.getline.When i use cin.getline for my code the name variable is not being read.It just skips the name variable and…
Arun
  • 111
  • 1
  • 1
  • 8
0
votes
5 answers

Beginner C++ Receiving Input in Multiple Ways

For an assignment, part of my program requires that I can receive 2 numbers from either a file or have them entered by hand. I can easily get them from a file by doing: int n1,n2; cin>>n1>>n2; That way, a file with contents simply reading something…
user1804208
  • 165
  • 2
  • 4
  • 9
0
votes
2 answers

Multiple User Input Choices C++

I am in a beginning C++ class, and right now we are going over functions. For an assignment I have to write two functions. One should take three int arguments representing a time (hours, minutes, seconds), and return the equivalent time in seconds.…
wgrenard
  • 187
  • 12
0
votes
1 answer

Why does this while loop never evaluate to true?

If the file has a list of coordinates and a character: (1,2,3,A) // blah blah (10,20,30,B) (11,22,33,C) the expression in the while loop never evaluates to true, Why is this? string str = ""; char aa, cc, ee, gg, hh, ii; int bb, dd, ff; while(cin…
0
votes
2 answers

C++ getline() delimitter

Hey I am trying to read in the following lines using a getline (15,0,1,#) (2,11,2,.) (3,20,0,S) I want to be able to just extract the integers as ints and the characters as char, but I have no idea how to only extract those.
0
votes
1 answer

Using cin.getline() and cin.get()

I'm having some trouble understanding how to use cin.getline and cin.get. I believe I understand the problem, just trying to figure out how to use them in conjunction possibly to solve a problem. I'm reading from a text file that's read in through…
user2817753
  • 1
  • 1
  • 1
  • 2
0
votes
1 answer

Reading in numbers with getline

I have a line that has the format (int,int,int,char) and wish to store the three ints into x,y,z and then place the char value into that position in my 3D array. However it is skipping the first number and going to the second. Any help? void…
GoBlue_MathMan
  • 1,048
  • 2
  • 13
  • 20
0
votes
2 answers

Problems checking for valid cin input

My code: http://pastebin.com/qjFd6KXb I have an assignment for class that requires me to create a program that will output a simple multiplication question that the user has to answer in three tries or less. One of the requirements is that the…
0
votes
2 answers

Reading Different Input Types C++

I am attempting to create a student object which takes the name, id, email, and three grades which are integers. My code is quite simple and is as follows: studentObj* newStudent = new studentObj; cout << "Student First Name: "; getline(cin,…
Barry Tormey
  • 2,966
  • 4
  • 35
  • 55
0
votes
5 answers

problems with filling the std::vector with while(cin >> x)

So I have a project for school that requires me to wait for the user to input Ctrl + Z to end a loop. The teacher said the best way to do this is to check for cin >> x and if this is true than they haven't entered in Ctrl + Z yet. Well after a bit…
0
votes
2 answers

C++ for loop skips cin.get()

In this for loop the cin.get(); is being skipped every other time. I have no idea why it is being skipped. Any help would be greatly appreciated. Code: for(Pointer = StartPointer; Pointer < EndPointer; Pointer += MemInfo.RegionSize) { …
user908759
  • 1,355
  • 8
  • 26
  • 48
0
votes
1 answer

Why cin doesn't recognize enter key, as cin.get does?

For example, if write those statements in code: char a[10]; char b[10]; cin>>a; cin>>b; cin>>b; doesn't see Enter key that was pressed after typing, for example, Hello but when instead cin>>b; write cin.get(b, 10); then cin.get(b, 10); reads Enter…
Sunrise
  • 1,311
  • 3
  • 18
  • 28
0
votes
1 answer

Why is this code snippet infinitely looping?

I'm fairly new to programming, and I'm trying to filter inputs from cin (for no particular reason; It is the only input method I know of right now) such that one can only enter 1-10 and get the "positive" response. Here is my code: #pragma region…
jwarner112
  • 1,492
  • 2
  • 14
  • 29
0
votes
0 answers

Crashing after reading with cin

For some reason the program always crashes the second time I main calls inputHolding() and tries to get the call number (the call number is entered and then it crashes). How do I fix this crash? Here is a picture of the call stack and where it is…
randomname
  • 265
  • 1
  • 9
  • 20
1 2 3
99
100