Thread: Cant understand the outout

  1. #1
    Registered User
    Join Date
    Jun 2011
    Location
    Bolpur, India
    Posts
    42

    Cant understand the outout

    Hi all I am new to Visual c++2008 sp1 as well as to this forum.I just downloaded it yesterday and tried to give it a shot.So I ran a program but the output it shows is in nor relation with the program.The file is:

    Code:
    #include<iostream>
    #include "stdafx.h"
    using namespace std;
    int main()
    {  int i;
    
    
    system("cls");
    
         cout<<"\n Enter the value of i=";
          cin>>i;
          cout<<"\n Result="<<i;
          system("pause");
          return 0;
    }
    and the output is like:

    Enter the value of i4

    i=4Press any key to continue..........

    As you can see this is not the correct output of the program.Please help!!!

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    It's wrong because you put the '\n' at the beginning. Where else to start a new line except at the end of the previous one....

  3. #3
    Registered User
    Join Date
    Jun 2011
    Location
    Bolpur, India
    Posts
    42
    I removed both the "\n"......No luck!!!

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
    #include<iostream>
    
    using namespace std;
    
    int main( void )
    {  int i;
    
         cout << Enter the value of i = ";
          cin >> i;
          cout << endl << "Result = "<< i << endl;
          cin;
          return 0;
    }

  5. #5
    Registered User
    Join Date
    Jun 2011
    Location
    Bolpur, India
    Posts
    42
    Quote Originally Posted by CommonTater View Post
    Code:
    #include<iostream>
    
    using namespace std;
    
    int main( void )
    {  int i;
    
         cout << Enter the value of i = ";
          cin >> i;
          cout << endl << "Result = "<< i << endl;
          cin;
          return 0;
    }
    error C2146: syntax error : missing ';' before identifier 'cin'

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You also need
    #include<iomanip>

    for the likes of endl

    > As you can see this is not the correct output of the program.Please help!!!
    It looked OK to me - perhaps you should also say what you expected to see as well.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Location
    Bolpur, India
    Posts
    42
    One more pitfall detected!!!
    The compiler shows the building logs of the files just recently compiled or built....!!It just donot build the file currently opened,already saved also!!!It just ignores the command to build the current file and shows the error messages of the last successfully or unsuccessfully built files...If the file was successfully built output of the previous file is showed when building the current file.Where is the problem?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    There are separate options (IIRC) to compile the current file (only) and do a build.

    Any "build" option will recompile (and link) every dependent change you did since the last "build" you did.

    Recompile current file should just compile the current file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #9
    Registered User
    Join Date
    Jun 2011
    Location
    Bolpur, India
    Posts
    42
    Recompile doesnot work.........It always links all the files present in the project folder.I want to know cant I run programs without opening the project option?Such as options like an "file" from "new"?

  10. #10
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    As far as I know, Visual Studio has always used project management.

    I have a sandbox project for all the stupid crap I post on here that I recycle for my purposes.

    Sorry about being dumb before.

  11. #11
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Yes in Visual Studio your files have to be included in a project to compile. If you just want to compile a single file without creating a project for it you have to do it manually from the command line.

  12. #12
    Registered User
    Join Date
    Jun 2011
    Location
    Bolpur, India
    Posts
    42
    So what should i do now?It always shows me the outputs of the last built program.Rebuilding doesnot work.Anybody has got any ideas?

  13. #13
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by mistu4u View Post
    Recompile doesnot work.........It always links all the files present in the project folder.
    Close the program before you try to recompile. The system will not allow you to over-write an active EXE file...


    I want to know cant I run programs without opening the project option?Such as options like an "file" from "new"?
    Open a command shell and run the program from there... you don't even need VS loaded at that point.

    You are creating executables, treat them as such.
    Last edited by CommonTater; 06-18-2011 at 02:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cant understand the outout
    By mistu4u in forum C Programming
    Replies: 5
    Last Post: 06-15-2011, 12:50 AM
  2. Don't understand this
    By .C-Man. in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2011, 07:01 AM
  3. -1.#J outout of sprintf
    By vart in forum C Programming
    Replies: 13
    Last Post: 03-03-2008, 01:26 PM
  4. help me understand...
    By stormfront in forum C Programming
    Replies: 2
    Last Post: 10-12-2005, 10:47 AM
  5. Help me out understand what I need to do please?
    By seal in forum C Programming
    Replies: 8
    Last Post: 10-11-2005, 10:31 PM