starting up a c++ project using visual C++ version 6

This is a discussion on starting up a c++ project using visual C++ version 6 within the C++ Programming forums, part of the General Programming Boards category; I have gotten a problem with the cin and cout not behaving properly. I have included <iostream> as I'm supposed ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    starting up a c++ project using visual C++ version 6

    I have gotten a problem with the cin and cout not behaving properly. I have included <iostream> as I'm supposed to, and modified cin and cout as std::cin and std::cout when using them (after searching through a bit online). However, I have gotten into a scenario where I can't see anything displayed properly and the program eventually crashing. From debugging the code, it appears that the cout and cin calls in my member functions were at fault. Could that be b/c I'm using Visual Studio version 6?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,166
    Could that be b/c I'm using Visual Studio version 6?
    That is possible. What is the code that you tried to compile with?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    Here is my CBulb.h:

    Code:
    class CBulb
    {
    private:
    	int state;		// state of the bulb (0=off, 1=on)		
    public:
    	void print(void);		// prints the value of state
    	void setstate(void);		// sets state = the new value entered
    };
    the source code for CBulb.cpp:
    Code:
    #include "CBulb.h"
    #include <iostream>
    
    void CBulb::print(void)
    {
    	std::cout<<"The value of state is "<<state<<std::endl ;
    }
    
    void CBulb::setstate(void)
    {
    	std::cin>>"Please enter the new value of the bulb state in 0(on) or 1(off) ">>state ;
    	std::cout<<" "<<std::endl;
    }
    and this is my driver cpp:
    Code:
    #include "CBulb.h"
    #include <iostream>
    
    void CBulb::print(void)
    {
    	std::cout<<"The value of state is "<<state<<std::endl ;
    }
    
    void CBulb::setstate(void)
    {
    	std::cin>>"Please enter the new value of the bulb state in 0(on) or 1(off) ">>state ;
    	std::cout<<" "<<std::endl;
    }
    They are compiled using "Multithreaded DLLs" run-time library on "Pentium" processor in the code generation settings of the project.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,166
    This is not correct as you are trying to read into a string literal:
    Code:
    std::cin>>"Please enter the new value of the bulb state in 0(on) or 1(off) ">>state ;
    It should be:
    Code:
    std::cout << "Please enter the new value of the bulb state in 0(on) or 1(off) ";
    std::cin >> state;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    Thank you. I got confused by the different links on the >> and << operators. Haven't done C++ programming in a while.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,166
    That said, I suggest you upgrade to MSVC8 or 9 (Visual C++ 2005 or 2008), or to the MinGW port of g++ 3.4.5 (which can be used with a number of IDEs including Code Blocks, Dev-C++, Eclipse and Netbeans).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    Very well aware of that myself, but I was told to use MSVC 6.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  2. Multiple Solutions in Visual C++ Project
    By Orion in forum C++ Programming
    Replies: 2
    Last Post: 01-26-2005, 10:16 PM
  3. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  4. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  5. <list>
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 02-24-2002, 04:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21