cin.get() not calling anything + how to find info?

I can't understand this program what cin.get() is supposed to accomplish here? It is not calling anything!

I googled it and found as only usage - to read istream e.g like from variable/array, example:
1
2
char array[25];
cin.get(array, 25);


Actual program where cin.get() occurs:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <iostream>
using namespace std;

char square[10] = { 'o','1','2','3','4','5','6','7','8','9' };

int checkwin();
void board();

int main()
{
    int player = 1, i, choice;

    char mark;
    do
    {
        board();
        player = (player % 2) ? 1 : 2;

        cout << "Player " << player << ", enter a number:  ";
        cin >> choice;

        mark = (player == 1) ? 'X' : 'O';

        if (choice == 1 && square[1] == '1')

            square[1] = mark;
        else if (choice == 2 && square[2] == '2')

            square[2] = mark;
        else if (choice == 3 && square[3] == '3')

            square[3] = mark;
        else if (choice == 4 && square[4] == '4')

            square[4] = mark;
        else if (choice == 5 && square[5] == '5')

            square[5] = mark;
        else if (choice == 6 && square[6] == '6')

            square[6] = mark;
        else if (choice == 7 && square[7] == '7')

            square[7] = mark;
        else if (choice == 8 && square[8] == '8')

            square[8] = mark;
        else if (choice == 9 && square[9] == '9')

            square[9] = mark;
        else
        {
            cout << "Invalid move ";

            player--;
            cin.ignore();
            cin.get();
        }
        i = checkwin();

        player++;
    } while (i == -1);
    board();
    if (i == 1)

        cout << "==>\aPlayer " << --player << " win ";
    else
        cout << "==>\aGame draw";

    cin.ignore();
    cin.get();
    return 0;
}

/*********************************************
    FUNCTION TO RETURN GAME STATUS
    1 FOR GAME IS OVER WITH RESULT
    -1 FOR GAME IS IN PROGRESS
    O GAME IS OVER AND NO RESULT
**********************************************/

int checkwin()
{
    if (square[1] == square[2] && square[2] == square[3])

        return 1;
    else if (square[4] == square[5] && square[5] == square[6])

        return 1;
    else if (square[7] == square[8] && square[8] == square[9])

        return 1;
    else if (square[1] == square[4] && square[4] == square[7])

        return 1;
    else if (square[2] == square[5] && square[5] == square[8])

        return 1;
    else if (square[3] == square[6] && square[6] == square[9])

        return 1;
    else if (square[1] == square[5] && square[5] == square[9])

        return 1;
    else if (square[3] == square[5] && square[5] == square[7])

        return 1;
    else if (square[1] != '1' && square[2] != '2' && square[3] != '3'
        && square[4] != '4' && square[5] != '5' && square[6] != '6'
        && square[7] != '7' && square[8] != '8' && square[9] != '9')

        return 0;
    else
        return -1;
}


/*******************************************************************
     FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/


void board()
{
    system("cls");
    cout << "\n\n\tTic Tac Toe\n\n";

    cout << "Player 1 (X)  -  Player 2 (O)" << endl << endl;
    cout << endl;

    cout << "     |     |     " << endl;
    cout << "  " << square[1] << "  |  " << square[2] << "  |  " << square[3] << endl;

    cout << "_____|_____|_____" << endl;
    cout << "     |     |     " << endl;

    cout << "  " << square[4] << "  |  " << square[5] << "  |  " << square[6] << endl;

    cout << "_____|_____|_____" << endl;
    cout << "     |     |     " << endl;

    cout << "  " << square[7] << "  |  " << square[8] << "  |  " << square[9] << endl;

    cout << "     |     |     " << endl << endl;
}

/*******************************************************************
                END OF PROJECT
********************************************************************/

How to find info:

My problem is: I have no idea how to find anything useful, search engines always find only similar examples and not thing I want, even if I put it in double quotes, or try words like cin.get() empty, or - modifier to exclude unwanted results... Google is also rigged, most useless engine for coding - I think...

Last time I tried 3 search engines, multiple keywords, code search engines, 3 tutorial sites and found nothing about initialization of bidimensional arrays, or 2-dimensional. Than after like 50 links I found only one site!!! Where there was only code and not explained how it works... It is not possible to do like this...

I mean maybe, if I read learncpp.com fully I would have idea about some things. But problem is, there are no exercises in these tutorials, so I Am forced to find some other exercises, which require knowledge I don't yet have. And search engines won't find absolutely anything! I need to practice to learn and to keep my sanity!

There are really no practice programs like first 10 sections :OOO, or so... While I did already like 10 practice programs from this forum and from others with pure basics... Because that site doesn't provide any exercises, but you can do so many things with so little already... But you need to have some ideas, or listed practice programs!!

I Am noob! So I have no idea: what I can do with all this code yet and I forget it too, if I don't practice it! I feel like reading these tutorials was useless, that I learned much more by practicing. Unless you have supermemory: who is gonna remember every technical word? They teach so many debugging options already at section 3 lol, what is gonna have usage for that, or remember all of that at that point except like 0.1% of people?

I learn ad hoc and I have ADHD: I can't bear reading 10-20 pages of only technical details, there is 0 creativity and it is pure tedium!!! My mind is not build like this. I actually learn backwards sometimes...

Code is actually simple at this level and I Am good at logic and have no trouble understanding concepts. Only problem is to find information, which I have no idea how to do... I think I tried what I could at this point...

I couldn't google errors and people told me last time, that you have to post on stackoverflow each time. Are you kidding?
1. it can take like 5-30 minutes, or like couple hours before answer - I don't like stopping current task
2. I don't have time to post each time I don't know something
3. it is a bad practice
4. that site is pedantic on grammar and I can't even write, I Am good at logic, not writing essays...

Even creator of C++ says 90% is only finding errors LOL and rest 9.9% is google-fest and 0.1% actual coding and creativity LOL

Also I read stroustrup book is full of errors and even primer has bad reviews! And learncpp says these books fail to teach habits, or what not to do. Also it is recommended finish learncpp basic tutorial before moving onto book for more complex concepts. I bet because programmers are terrible at explaining/writing.

Tho I think learncpp is a great tutorial, but it woefully missing practice programs at end of each section and ideas what to do! As I already find out, with that knowledge I could do so many things, which weren't there! I don't know maybe other people are different, but I have aphantasia - meaning no imagination. I need to deduce it somehow, I Am creative logically. I can't create things, I Am good at solving logic puzzles, but if you asked me to make even simple one - I couldn't do it!

People say they learned nothing in school and in 45 class still didn't understand a concept, but got it from 9 minute video from bucky LOL...

Can you recommend some search engine for C++, or how to find statements, expressions and what not??? What they do? And these reference sites are too technical, I don't understand them yet. Besides cppreference.com didn't find even cin.get()... WTH? I would think search engines would find something, but they don't that is the thing! Really strange!
cin.get() is only there to stop a console window vanishing as soon as the program has finished and before you have had time to read the output. It waits for you to enter a character. It doesn't do anything with it; its role is just to buy time for the user.

It seems to be mainly there for people who use a certain IDE and who haven't adjusted the settings so as not to shut the output window immediately on completion.

It's an irrelevant part of the program.

The definition is here:
http://www.cplusplus.com/reference/istream/istream/get/
get() is just a member function of the istream object cin.

I would ignore reviews and just choose a book you are happy with. Some "good" books do not look appropriate for self-learning beginners. The one I taught myself c++ from is routinely panned. But there are advantages to having programmed in other languages before.
Last edited on
Huh. Hmm... Okay.

First, understand your position. You call yourself a noob, but I don't think you quite grasp the consequences of your lack of knowledge and experience. Programmers generally find sites such as Google, StackOverflow, and cppreference quite useful when looking for some information they need. If you can't figure out how to use them effectively that's fine, but realize it's an issue with you, not with the sites or the information they contain. Simply put, if you ask the wrong questions you will get useless answers.
If you're able to understand your position of complete ignorance, you should realize that you need to learn from someone who knows more than you. Someone who wrote a book is not a bad place to start. Given that, whether their book is "full of errors" or not is not really important. Even if the information is only 90% accurate (it will almost certainly be much more accurate than that), by the time you finish you will still know more correct information than when you started.

Second,
I don't know maybe other people are different, but I have aphantasia - meaning no imagination. I need to deduce it somehow, I Am creative logically. I can't create things
That's kind of a problem. Programming is all about making machines that solve problems. If you can't think up problems for yourself to solve, sooner or later you will run into the problem that there's no one there to give you a task to do. Imagine you manage to find the ideal tutorial for you, with tons of practice problems at the end of each section. What will you do when you inevitably get to the end?
empleat wrote:
I have aphantasia - meaning no imagination. I need to deduce it somehow, I Am creative logically. I can't create things, I Am good at solving logic puzzles, but if you asked me to make even simple one - I couldn't do it!


If you can't even create a simple logic puzzle, you will not be good at programming. If you have "no imagination," you will absolutely suck at programming. If you "can't create things," you should find a job digging ditches somewhere. Or go into politics– are you a good liar?

Also, if you're finding that these websites are too technical, start with something more your level. Try finding a beginners C++ book and start there. And PRACTICE! I can't stress that enough, if you don't practice, you WILL NOT LEARN SQUAT!

A good book to start with is "Starting out with C++: Early Objects," by Gaddis, Walters, and Muganda. You can find it on pearsonhighered.com. Get the newest edition, or if you can't at least get the 9th, it has C++11 which, although old, is not prehistoric like C++98 (what I first learned).
I can't bear reading 10-20 pages of only technical details, there is 0 creativity and it is pure tedium!!!


Then I suggest you're going to struggle somewhat. Learning C++ well IMO involves a lot of reading - both of books and on-line resources (reference sites, blogs etc).

Besides cppreference.com didn't find even cin.get()... WTH?


Search cppreference for get() gives:

https://en.cppreference.com/w/cpp/io/basic_istream/get

.get() is a istream method and cin is an istream. But yes, unless you knew that you'd probably have difficulty finding this. cppreference and other sites are reference sites - not teaching sites.

For learning c++, my recommendation is Beginning C++20: From Novice to Professional by Ivor Horton. I'm not a fan of Stroustrup's books - but I know others that swear by them. There are many introductory book to c++ available. To a some what large extent it's often down to personal preference as to which book suits. Agent Max suggest the Gaddis book. I agree that this is a good book - in IMO is overpriced.

PS. I find the reference section of this website to be easier to use/read (if not wanting C++17/20 which isn't covered).

eg for cin.get().

cin is input/ouput, so select this from reference. It is istream so then choose that, then classes istream. Which gets http://www.cplusplus.com/reference/istream/istream/

Then scroll down to get() and you get http://www.cplusplus.com/reference/istream/istream/get/

Last edited on
I just want to point out, like @seeplus said, the Gaddis book is expensive (about $130 USD or so), but it comes with a zip file that contains example programs that you can download and test.

Alternatively, if you want I can post them on Pastebin and give you the link and you can get them that way ;)
That is the thing I don't have imagination, but I Am very creative, maybe in logic - not sure what it is exactly. Maybe because I have ADHD, I see from 1 thing another 20 things and from them another 20 things. Some sort of like permutations generator :D

Nice book with examples that would be the first one :D :D :D

cin is input/ouput, so select this from reference. It is istream so then choose that, then classes istream. Which gets http://www.cplusplus.com/reference/istream/istream/

Yeah makes sense, I tried to find it by keyword didn't think about this at the time, I have huge headache!

Okay this helps, thank you all!
empleat wrote:
I don't have imagination, but I Am very creative

If you don't have imagination, how can you be creative? It doesn't work that way. And if you have ADHD, that doesn't necessarily mean you don't have imagination or can't be creative (at least as far as I know).

I see from 1 thing another 20 things and from them another 20 things

If this means what it seems to mean, then I'n guessing you do have imagination; it takes a pretty good imagination to see 20 things when only given one!

Often I can see solutions that other people don't, and then some other guy will show me a different solution that's a lot shorter, or less complicated as mine was ;)

So it's really a matter of perspective, in my opinion. Different experiences result in different points of view, which results in people giving different solutions to a problem. That's why working in groups works so well for stuff like software developing, because you get many different solutions, and some of them can be shorter, less complicated, or work better than others. And when you combine them all together, it results in a better program than any one person could have made on their own!
Topic archived. No new replies allowed.