Menu

Code Newbie help

storm13
2007-09-01
2012-09-26
  • storm13

    storm13 - 2007-09-01

    I put this and it doesnt write any letters in the screen.


    include <iostream>

    int main()
    {
    char response;
    std::cin >> response;
    using std::cout;
    using std::endl;

    cout << "Hello there.\n";
    cout << "Here is 5: " << 5 << "\n" ;
    cout << "The manipulator endl ";
    cout << "writes a new line to the screen.";
    cout << endl;
    cout << "here is a very big number:\t" << 70000;
    cout << endl;
    cout << "Here is the sum of 8 and 5:\t";
    cout << 8+5 << endl;
    cout << "here's a fraction:\t\t";
    cout << (float) 5/8 << endl;
    cout << "and a very very big number:\t";
    cout << (double) 7000 * 7000 << endl;
    cout << "don't forget to replace jesse liberty ";
    cout << "with your name..\n";
    cout << "Ermis Vassilopoulos is a c++ Programmer!\n";
    return 0;
    }


    The console box appears but it doesnt write anything in it. Why ?

     
    • Osito

      Osito - 2007-09-01

      Perhaps it got offended by your last cout statement? :) It worked fine for me. When you run it, are you actually typing something and hitting enter so that it gets past the cin statement? The screen will remain blank until you type at least one character and hit enter.

       
    • Wayne Keen

      Wayne Keen - 2007-09-01

      Please post your compile log. Before you say something like "But Wayne,that's all
      you ever ask for" - I am looking for something very specific - you see, if you compile
      a console program with -mwindows - you will not see your prints.

      The compile log is on the tab labeled "Compile Log", NOT the tab labeled compiler,
      and the right mouse button brings up the copy menu.

      Wayne

       
    • storm13

      storm13 - 2007-09-01

      ojkay when i wrote something and pressed enter, it did say something but so fast that i couldnt see.
      My book says that if I use

      char response;
      std::cin >> response;

      it wont be fixed

      but no it doesnt work

      Compiler: Default compiler
      Executing g++.exe...
      g++.exe "C:\Dev-Cpp\wewe.cpp" -o "C:\Dev-Cpp\wewe.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
      Execution terminated
      Compilation successful


      Osito at first i got angry with you but then i laughed.

      this shouldnt be happening (also me programming shouldnt eb happening)

       
      • Osito

        Osito - 2007-09-01

        When I tested your code I added another std::cin >> response; at the end so the window wouldn't close until I typed another char and hit enter. There are better ways but I'm lazy and a copy/paste was easy.

         
    • storm13

      storm13 - 2007-09-01

      no still have the problem because its my third day in programming and i already hate it

       
      • Wayne Keen

        Wayne Keen - 2007-09-01

        Storm,

        Have you read the thread titled "Please Read Before Posting a Question" - there
        is a thread there that deals with the "keeping the window open" problem.

        It also has a LOT of other useful information.

        I encourage you to be patient. I doubt there are too many worthwhile things
        that you have been good at in 3 days.

        Wayne

         
    • Anonymous

      Anonymous - 2007-09-01

      If you run this code from the IDE or from explorer, it will work (and does work), but you have to realise that when a program terminates, its window is closed by the OS. This is normal behaviour. Your code will print all that output, probably faster than you can perceive it, and then close the window. You need to add code to let it wait before closing the window.

      And you also need to understand the behaviour of line bases console input, it may trip you up, and still appear to immediately close. Hint: You input a 'response' character, you press 'a', then '<enter>' - that's two characters.

      Clifford

       
      • Anonymous

        Anonymous - 2007-09-02

        "line bases" -> "line based"

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.