Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

'cin' Isn't working

Code
// sa.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{

    cin >> hello;




    return 0;
}

please what am i doing wrong here?
I know this is a troll but just in case it is not.
Code
int hello;
cin >> hello;
Hope that gave you an idea on whats wrong.
(Aug 14, 2017 08:43 AM)CortexM4 Wrote:  I know this is a troll but just in case it is not.
Code
int hello;
cin >> hello;
Hope that gave you an idea on whats wrong.

Not a troll. I just started today and im taking it pretty seriously and not leaving anything out. I got like 3 books from my library lmao
I also started learning C++ today. Found a recent free tutorial that is pretty good so far:

-snip-
EDIT: I guess the site is considered Warez.


How dated are the books you're using?
(Aug 14, 2017 08:48 AM)Fυcĸleѕѕ Wrote:  I also started learning C++ today. Found a recent tutorial that is pretty good so far:

-snip-
EDIT: I guess the site is considered Warez.


How dated are the books you're using?

I dont know. There from a libary so probulary pretty old
2011.... :/ is that ok?
I would suggest learning C first.
Heres the classic one:
https://github.com/germanoa/compiladores...nighan.pdf

Proper ebook version:
http://yunus.hacettepe.edu.tr/~yurdugul/3/C/c.pdf


Once you learn C you will know how memory works and how to work with it, only then focus on C++ and all of it's advanced features.

I also suggest you read this in parallel, it helps understanding the underlying architecture and how your code ends up executing on a computer.
http://joe90.yolasite.com/resources/Insi...achine.pdf

C++ is quite massive for a total beginner.
How about reading the compiler warnings as a start? I'm pretty sure the error message for this one should be self-explanatory and won't be 100 lines like some other C++ errors.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
You might want to try initialise a variable before you try to use it. Keep learning because getting input for Strings is different than with numbers.
(Aug 14, 2017 04:51 PM)Hapi Wrote:  You might want to try initialise a variable before you try to use it. Keep learning because getting input for Strings is different than with numbers.

It can be the same in terms of how input streams work and std::basic_string<char> (std::string). There's a limitation, but if it doesn't matter with the string value requirements, then you wouldn't be able to tell much of a difference.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Aug 14, 2017 04:51 PM)Hapi Wrote:  You might want to try initialise a variable before you try to use it. Keep learning because getting input for Strings is different than with numbers.
Louka is that you?
Code
#include <iostream>

using namespace std;

int hello; //you miss this line.

int main() {
    cin >> hello;
}

declared the the 'hello' first. Cheers
(Aug 15, 2017 07:38 AM)Zens Wrote:  
Code
#include <iostream>

using namespace std;

int hello; //you miss this line.

int main() {
    cin >> hello;
}

declared the the 'hello' first. Cheers

Exactly what this user said, you need to declare the integer first and then assign a value to it using cin
evening chaps
(Aug 15, 2017 07:38 AM)Zens Wrote:  ...
declared the the 'hello' first. Cheers

Why global?...


Code
#include "stdafx.h"
#include <iostream>

int main()
{
    int hello; // local variable
    if ((std::cin >> hello))
    {
        std::cout << hello;
    }
    else /* failure */ {}
}
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]
(Aug 15, 2017 09:17 AM)0xDEAD10CC Wrote:  Why global?...
In his defense, it's just an example, I'm sure that if OP put some time in to it he would learn proper programming practices.
(Aug 15, 2017 09:31 AM)CortexM4 Wrote:  In his defense, it's just an example, I'm sure that if OP put some time in to it he would learn proper programming practices.

It's just as easy to provide him with good programming practices instead of assuming he will understand that what you're giving him isn't the best way to do things. Same amount of code, different scope/line.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by Quality_k1nGSep 27, 2018 07:05 PM 6 292 Sep 27, 2018 07:05 PM
Last Post: Quality_k1nG
[C] by F.A.S.TJul 22, 2018 10:57 AM 1 119 Jul 22, 2018 10:57 AM
Last Post: aeiro
[Java] by txkhaarOct 26, 2017 08:19 AM 1 630 Oct 26, 2017 08:19 AM
Last Post: XMR