Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: [C++] Executable does nothing when running simple iostream program  (Read 10012 times)

0 Members and 1 Guest are viewing this topic.

SLiV

    Topic Starter


    Rookie

  • Reject only your ignorance and you may survive.
    I was trying to make a program that simulates a cardgame, but I run on to something at the very start. I wasn't able to figure out what I or it was doing wrong, since it doesn't run it at all. No error, no bleeps, no blank screens. Nothing. Just a flash.

    Code: [Select]
    #include <iostream.h>

    int main()
    {
        int a;
        char clr[5] = {'o','h','d','s','c'};
        char nmr[10] = {'0','A','J','Q','K','@','#','7','8','9'};
         
        cout << "The Jack of Spades (3;2) is abbreviated: " << clr[3] << "" << nmr[2];
         
           
        cout << "How Awesome...";
       
        cin.get();
        return 0;
    }
    This is not an extract, this is in fact the whole code. That's what bothers me about it.
    I know I could use "ohdsc" instead, but that shouldn't mather, right? Also, clr[5] has 5 variables, clr[0]-clr[4], so that should work as well.
    Maybe it thinks I want to define nmr[5] instead of the whole nmr range, but I don't know how else to define it. I almost copied it from the book I'm working with, so what is happening?

    I'm running it with Dev-C++ and Vista.
    « Last Edit: November 29, 2009, 11:45:00 AM by SLiV »
    "When's a croquet mallet like a billy club? I'll tell you: whenever you want it to be." - Cheshire Cat

    TheUnixGuy



      Beginner

      Thanked: 7
      Re: [C++] Executable does nothing when running simple iostream programme
      « Reply #1 on: November 29, 2009, 03:45:39 AM »
      Hello,

      Try making:
      Code: [Select]
      #include <iostream.h>
      ...

      to
      Code: [Select]
      #include <iostream>
      ...

      NOTE: We write 'programs' not 'programmes'.
      When it rains, most birds head for shelter; Eagle is the only bird that flies above the clouds to avoid rain.

      SLiV

        Topic Starter


        Rookie

      • Reject only your ignorance and you may survive.
        Re: [C++] Executable does nothing when running simple iostream programme
        « Reply #2 on: November 29, 2009, 11:44:41 AM »
        I tried that, because that was what Dev-C++ suggested. Unfortunatly it immediatly errored that the function 'cout' was first declared etc.
        "When's a croquet mallet like a billy club? I'll tell you: whenever you want it to be." - Cheshire Cat

        BC_Programmer


          Mastermind
        • Typing is no substitute for thinking.
        • Thanked: 1140
          • Yes
          • Yes
          • BC-Programming.com
        • Certifications: List
        • Computer: Specs
        • Experience: Beginner
        • OS: Windows 11
        Re: [C++] Executable does nothing when running simple iostream program
        « Reply #3 on: November 29, 2009, 11:56:08 AM »
        this works for me- in Visual Studio 2008:

        Code: [Select]

        #include <iostream>
        #include <ctime>
        using namespace std;
        int _tmain(int argc, _TCHAR* argv[])
        {

            int a;
            char clr[5] = {'o','h','d','s','c'};
            char nmr[10] = {'0','A','J','Q','K','@','#','7','8','9'};
             
            cout << "The Jack of Spades (3;2) is abbreviated: " << clr[3] << "" << nmr[2];
             
               
            cout << "How Awesome...";
           
            cin.get();
            return 0;

        }


        just ignore the tmain part there- I'm sure you can use main() as you are doing instead. I just went with the template it gave me.
        you might want to add a endl to the end of the first cout call, though; otherwise, the entire program writes to one line.

        Code: [Select]
            cout << "The Jack of Spades (3;2) is abbreviated: " << clr[3] << "" << nmr[2] << endl;
        I was trying to dereference Null Pointers before it was cool.

        SLiV

          Topic Starter


          Rookie

        • Reject only your ignorance and you may survive.
          Re: [C++] Executable does nothing when running simple iostream program
          « Reply #4 on: November 30, 2009, 01:59:30 AM »
          So you're suggesting that I'd add #include <ctime> and using namespace std;?

          And yeah, I should probably add an endline, but that's not the real issue here.
          "When's a croquet mallet like a billy club? I'll tell you: whenever you want it to be." - Cheshire Cat

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: [C++] Executable does nothing when running simple iostream program
          « Reply #5 on: November 30, 2009, 02:14:29 AM »
          oh.. ignore the ctime include too. the namespace directive couldn't hurt, though.
          I was trying to dereference Null Pointers before it was cool.

          SLiV

            Topic Starter


            Rookie

          • Reject only your ignorance and you may survive.
            Re: [C++] Executable does nothing when running simple iostream program
            « Reply #6 on: December 01, 2009, 02:13:51 PM »
            What do you mean 'couldn't hurt'?

            Then what did you add?

            Just the endline? Because that's obviously not the error.

            I checked them both, with no improvements whatsoever. I'm not sure you read the topic start carefully. Or at all.
            "When's a croquet mallet like a billy club? I'll tell you: whenever you want it to be." - Cheshire Cat

            BC_Programmer


              Mastermind
            • Typing is no substitute for thinking.
            • Thanked: 1140
              • Yes
              • Yes
              • BC-Programming.com
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 11
            Re: [C++] Executable does nothing when running simple iostream program
            « Reply #7 on: December 01, 2009, 02:54:00 PM »
            What do you mean 'couldn't hurt'?

            Then what did you add?

            Just the endline? Because that's obviously not the error.

            I checked them both, with no improvements whatsoever. I'm not sure you read the topic start carefully. Or at all.

            Quote
            this works for me- in Visual Studio 2008:


            the code I posted works fine for me; I can see the output just fine. And notice I actually didn't add the endl; it was merely a suggestion. I pasted your code into VS2008 and tweaked it until it compiled and ran and then posted the code I had at that point. the <ctime> was from the program template I loaded; I simply forgot to remove it.

            I just downloaded Dev C++; copy-pasted your code- and it compiled and ran fine. a few warning about deprecation or something, but it ran just fine.

            EDIT:

            the console window output was:

            Code: [Select]
            The Jack of Spades (3;2) is abbreviated: sJHow Awesome...
            and the window stayed visible until I closed it; this was a fresh install of Dev C++, so I hadn't fiddled with any options.
            I was trying to dereference Null Pointers before it was cool.

            Salmon Trout

            • Guest
            Re: [C++] Executable does nothing when running simple iostream program
            « Reply #8 on: December 01, 2009, 03:42:40 PM »
            Quote
            I'm not sure you read the topic start carefully. Or at all.

            Check the attitude at the door, please.

            TheUnixGuy



              Beginner

              Thanked: 7
              Re: [C++] Executable does nothing when running simple iostream program
              « Reply #9 on: December 02, 2009, 02:18:44 AM »
              Hello,

              In case BC_Programmer's method doesn't work out, try running the program from the command line or whatever MS Vista calls it. Just CD into that directory and type its name as if it were a command.
              When it rains, most birds head for shelter; Eagle is the only bird that flies above the clouds to avoid rain.

              SLiV

                Topic Starter


                Rookie

              • Reject only your ignorance and you may survive.
                Re: [C++] Executable does nothing when running simple iostream program
                « Reply #10 on: December 02, 2009, 09:35:58 AM »
                @Salmon Trout / BC_Programmer
                Sorry, I didn't mean to be rude, as it is me who is asking your help; I'm just getting irritated by a lot of things not working.

                @Topic
                My point being, BC_Programmer has no method, and shouldn't. Because apparently the code contains no bugs at all. But then why isn't my pc able to run it?

                About the command line, I'm not that good. But creating an exe and running that doesn't work either, and running it only partially won't do because Dev-C++ says there is no Debugging Information. Clicking on 'create' doesn't seem to improve anything.

                So probably either my DevC++ is causing it, or my pc. The problem remaining, what should I do about it?
                "When's a croquet mallet like a billy club? I'll tell you: whenever you want it to be." - Cheshire Cat

                Salmon Trout

                • Guest
                Re: [C++] Executable does nothing when running simple iostream program
                « Reply #11 on: December 02, 2009, 09:44:29 AM »
                Quote
                it doesn't run it at all. No error, no bleeps, no blank screens. Nothing. Just a flash.

                Have you tried running the exe by typing its name at an already open command prompt? (i.e. not from Windows Explorer by clicking in its icon) At least that way you might see some informative messages.


                TheUnixGuy



                  Beginner

                  Thanked: 7
                  Re: [C++] Executable does nothing when running simple iostream program
                  « Reply #12 on: December 02, 2009, 09:48:10 AM »
                  Hello,


                  About the command line, I'm not that good.

                  If you're using MS Vista, click on Start and type "cmd" and press ENTER. [1] The command prompt will appear. Copy your program into D: Drive (using My Computer) and rename it to "newprog1" (without  quotes).  Type "D:" into the command prompt and press ENTER. Type in "newprog1.exe" and press ENTER. Your program should run and display correctly.

                  [1]: http://www.computerhope.com/issues/chdos.htm#02

                  NOTE: I recommend learning the command line before diving into programming.
                  When it rains, most birds head for shelter; Eagle is the only bird that flies above the clouds to avoid rain.

                  SLiV

                    Topic Starter


                    Rookie

                  • Reject only your ignorance and you may survive.
                    Re: [C++] Executable does nothing when running simple iostream program
                    « Reply #13 on: December 02, 2009, 01:50:41 PM »
                    Just running the .exe in the current folder did nothing either; the D: drive is a CD/DVD drive, so I don't think that'll work either.
                    Maybe you mean C:? But entering the command "C:" (without quotes) was not recognised as a command.
                    "When's a croquet mallet like a billy club? I'll tell you: whenever you want it to be." - Cheshire Cat

                    TheUnixGuy



                      Beginner

                      Thanked: 7
                      Re: [C++] Executable does nothing when running simple iostream program
                      « Reply #14 on: December 03, 2009, 01:38:02 AM »
                      Hello,

                      Just running the .exe in the current folder did nothing either

                      Through command line?  I would try another compiler.
                      When it rains, most birds head for shelter; Eagle is the only bird that flies above the clouds to avoid rain.