Thread: C++ Variables - Tutorial example not working

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    3

    Unhappy C++ Variables - Tutorial example not working

    Hello,

    In the c++ tutorial there is a section on variables just after the first hello world program.

    Using dev cc i have entered and compiled the example code that is included in the tute, but when i try to run it nothing happens.

    What should i do?

    I have made sure i have entered the code exactly as written, and the previous example codes worked fine...
    The code is as follows:
    Code:
    #include <iostream> using namespace std; int main() { int thisisanumber; cout<<"Please enter a number: "; cin>> thisisanumber; cin.ignore(); cout<<"You entered: "<< thisisanumber <<"\n"; cin.get(); }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    What do you mean by "nothing happens"?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    Exactly that... nothing. I compile the program, save it, and try to run it but nothing at all changes or happens. No program window. no discernable event of any kind. The window just stays the same.

    But when I try to run the "hello world" program using the same tools all works fine. I'm really confused...

  4. #4
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    Did you try "Compile and run"? You can just press F9. I tried compiling this on my machine with the latest version of Dev-C++, but got a message from AVG stating that this contained a trojan. Maybe your antivirus is blocking it behind the scenes.
    Can anyone else find anything malicious about this code? I changed "\n" to endl and it ran just fine without any intervention from AVG.
    Last edited by linucksrox; 02-26-2012 at 10:31 PM.
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by linucksrox
    I tried compiling this on my machine with the latest version of Dev-C++, but got a message from AVG stating that this contained a trojan. Maybe your antivirus is blocking it behind the scenes.
    Can anyone else find anything malicious about this code? I changed "\n" to endl and it ran just fine without any intervention from AVG.
    It is clearly a false positive from AVG.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    Right, but I wonder what AVG is seeing as suspicious behavior. Regardless, I compiled using Codeblocks and it worked without any issues. I'd recommend uninstalling Dev-C++ and updating to Codeblocks since it's more up to date.
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    3
    Thanks guys you were right. I turned avg off through the task manager and the program immediately ran. I wonder what causes this? Do you think it will be a common problem? Should i switch to a different compiler before continuing the tutorial? You mentioned codeblocks, is that the best to use?

  8. #8
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by muttley View Post
    Thanks guys you were right. I turned avg off through the task manager and the program immediately ran. I wonder what causes this? Do you think it will be a common problem? Should i switch to a different compiler before continuing the tutorial? You mentioned codeblocks, is that the best to use?
    Code::Blocks is an IDE, the compiler is up to you( mingw is generally used)
    You can try by configuring your antivirus properly..as to trust the compiler.

  9. #9
    Advanced Novice linucksrox's Avatar
    Join Date
    Apr 2004
    Location
    Michigan
    Posts
    198
    Also I'd recommend setting AVG to alert you when it finds threats, so you know when it's blocking a program.
    "What are all you parallelograms doing here?" - Peter Griffin (to Joe and his wheelchair buddies)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 17
    Last Post: 09-15-2011, 11:56 AM
  2. Sockets tutorial, datagram sockets example not working for me
    By caesius in forum Networking/Device Communication
    Replies: 14
    Last Post: 12-26-2009, 03:40 PM
  3. Replies: 6
    Last Post: 12-02-2009, 08:47 AM
  4. Working with variable variables
    By Differentialpi in forum C Programming
    Replies: 1
    Last Post: 01-06-2008, 10:35 PM
  5. Winprog BMP tutorial not working
    By Brigs76 in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2005, 07:36 PM

Tags for this Thread