Results 1 to 13 of 13

Thread: Learning and doing Visual C++

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2014
    Location
    Canada, British Columbia
    Posts
    54

    Learning and doing Visual C++

    Okie doked guys, so i have started......*ahem*..."Learning" about Visual C++ and I need some help from y'all about where i can find any resources and tools, PDF's, or anything that can help me learn about C++. I found a little tutorial online about making some sort of clock, anc i put the code into use, but for some reason, when i try to run the program, it exits almost immediately, and in the Debug Output box it says
    Code:
    'HelloWorld!.exe' (Win32): Loaded 'C:\Users\Mateusz Wierzbicki\Documents\Visual Studio 2013\Projects\HelloWorld!\Debug\HelloWorld!.exe'. Symbols loaded.
    'HelloWorld!.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
    'HelloWorld!.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
    'HelloWorld!.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
    'HelloWorld!.exe' (Win32): Loaded 'C:\Windows\System32\msvcp120d.dll'. Symbols loaded.
    'HelloWorld!.exe' (Win32): Loaded 'C:\Windows\System32\msvcr120d.dll'. Symbols loaded.
    The program '[3132] HelloWorld!.exe' has exited with code 0 (0x0).
    The reason it says "HelloWorld!" is because i started with that tutorial, but moved on in the same project, coz that one wasn't also functioning, giving me the same "Exited with code 0 (0x0)"

    Here are the pieces of code from my other 3 Tabs of main code
    TAB 1: Time in this demo.ccp
    Code:
    // Implementation file for Time.h
    // Member function definitions for Time class.
    #include <iostream>
    using std::cout;
    #include "time.h"
    // Time constructor initializes each data member to zero.
    Time::Time() {
    	hour = minute = second = 0;
    }
    // Set a new Time value using military time. Perform validity
    // checks on the data values. Set invalid values to zero. 
    void Time::setTime(int h, int m, int s)
    {
    	hour = (h >= 0 && h < 24) ? h : 0;
    	minute = (m >= 0 && m < 60) ? m : 0;
    	second = (s >= 0 && s < 60) ? s : 0;
    }
    // Print Time in military format
    void Time::printMilitary()
    {
    	cout << (hour < 10 ? "0" : "") << hour << ":" << (minute < 10 ? "0" : "") << minute;
    }
    // Print time in standard format
    void Time::printStandard()
    {
    	cout << ((hour == 0 || hour == 12) ? 12 : hour % 12)
    		<< ":" << (minute < 10 ? "0" : "") << minute
    		<< ":" << (second < 10 ? "0" : "") << second
    		<< (hour < 12 ? " AM" : " PM");
    }
    TAB 2: TimeDemo.ccp
    Code:
    // Driver for Time class
    #include <iostream>
    using std::cout;
    using std::endl;
    #include "time.h"
    // Driver to test class Time
    int main()
    {
    	Time t;
    	// instantiate object t of class time
    	cout <<
    		"The initial military time is ";
    	t.printMilitary();
    	cout << "\nThe initial standard time is ";
    		t.printStandard();
    	t.setTime(13, 27, 6);
    	cout << "\n\nMilitary time after setTime is ";
    		t.printMilitary();
    	cout << "\nStandard time after setTime is ";
    		t.printStandard(); t.setTime(99, 99, 99);
    	// attempt invalid settings
    	cout << "\n\nAfter attempting invalid settings : \n" << "Military time : ";
    		t.printMilitary();
    	cout << "\nStandard time : ";
    		t.printStandard();
    	cout << endl;
    }
    TAB 3: Time.h
    Code:
    // Time class header file
    // Member functions are defined in time.cpp
    // prevent multiple inclusions of header file
    #ifndef TIME1_H
    #define TIME1_H
    // Time abstract data type definition
    class Time {
    public: Time();
    		// constructor
    		void
    			setTime(int, int
    			, int);
    		// set hour, minute, second
    		void printMilitary();
    		// print military time format
    		void printStandard();
    		// print standard time format
    private:
    	int hour;
    	// 0 - 23
    	int minute;
    	// 0-59
    	int second;
    	// 0-59
    };
    #endif
    Thanks for the help
    Best Regards
    ~Mister_Meh
    ~Mister_Meh

  2. #2
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    For learning c++ I would suggest you look at these sites
    http://www.learncpp.com/
    http://www.cplusplus.com/doc/tutorial/
    http://www.cprogramming.com/tutorial...al.html?mb=top

    I would also suggest that you invest in a good c++ book. I can recommend some if you want.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    I would expect this program to exit almost immediately as it only display some info to the console screen. I've merged it all together into one module for testing
    Code:
    #include <iostream>
    using namespace std;
    
    class Time {
    public: 
    	Time();
    	void setTime(int, int , int);
    	void printMilitary();
    	void printStandard();
    
    private:
    	int hour;
    	int minute;
    	int second;
    };
    
    Time::Time() : hour(0), minute(0), second(0) {}
    
    void Time::setTime(int h, int m, int s)
    {
    	hour = (h >= 0 && h < 24) ? h : 0;
    	minute = (m >= 0 && m < 60) ? m : 0;
    	second = (s >= 0 && s < 60) ? s : 0;
    }
    
    void Time::printMilitary()
    {
    	cout << (hour < 10 ? "0" : "") << hour << ":" << (minute < 10 ? "0" : "") << minute;
    }
    
    void Time::printStandard()
    {
    	cout << ((hour == 0 || hour == 12) ? 12 : hour % 12)
    		<< ":" << (minute < 10 ? "0" : "") << minute
    		<< ":" << (second < 10 ? "0" : "") << second
    		<< (hour < 12 ? " AM" : " PM");
    }
    
    int main()
    {
    Time t;
    
    	cout << "The initial military time is ";
    	t.printMilitary();
    
    	cout << "\nThe initial standard time is ";
    	t.printStandard();
    
    	t.setTime(13, 27, 6);
    	cout << "\n\nMilitary time after setTime is ";
    	t.printMilitary();
    	cout << "\nStandard time after setTime is ";
    	t.printStandard();
    
    	t.setTime(99, 99, 99);
    	cout << "\n\nAfter attempting invalid settings : \n" << "Military time : ";
    	t.printMilitary();
    	cout << "\nStandard time : ";
    	t.printStandard();
    
    	cout << endl;
    }
    This display so the console
    Code:
    The initial military time is 00:00
    The initial standard time is 12:00:00 AM
    
    Military time after setTime is 13:27
    Standard time after setTime is 1:27:06 PM
    
    After attempting invalid settings :
    Military time : 00:00
    Standard time : 12:00:00 AM
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  4. #4
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    A slightly more standard 'c++' code would be
    Code:
    #include <iostream>
    #include <iomanip>
    using namespace std;
    
    class Time {
    public: 
    	Time(unsigned int h = 0, unsigned int m = 0, unsigned int s = 0);
    	void setTime(unsigned int h, unsigned int m, unsigned int s);
    	void printMilitary() const;
    	void printStandard() const;
    
    private:
    	unsigned int hour;
    	unsigned int minute;
    	unsigned int second;
    };
    
    Time::Time(unsigned int h, unsigned int m, unsigned int s)
    {
    	setTime(h, m, s);
    }
    
    void Time::setTime(unsigned int h, unsigned int m, unsigned int s)
    {
    	hour = (h < 24) ? h : 0;
    	minute = (m < 60) ? m : 0;
    	second = (s < 60) ? s : 0;
    }
    
    void Time::printMilitary() const
    {
    	cout << setw(2) << setfill('0') << hour << ":" << setw(2) << setfill('0') << minute;
    }
    
    void Time::printStandard() const
    {
    	cout << ((hour == 0 || hour == 12) ? 12 : hour % 12) 
    		<< ":" << setw(2) << setfill('0') << minute 
    		<< ":" << setw(2) << setfill('0') << second
    		<< (hour < 12 ? " AM" : " PM");
    }
    
    int main()
    {
    Time t;
    
    	cout << "The initial military time is ";
    	t.printMilitary();
    
    	cout << "\nThe initial standard time is ";
    	t.printStandard();
    
    	t.setTime(13, 27, 6);
    	cout << "\n\nMilitary time after setTime is ";
    	t.printMilitary();
    	cout << "\nStandard time after setTime is ";
    	t.printStandard();
    
    	t.setTime(99, 99, 99);
    	cout << "\n\nAfter attempting invalid settings : \n" << "Military time : ";
    	t.printMilitary();
    	cout << "\nStandard time : ";
    	t.printStandard();
    
    	cout << endl;
    }
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: Learning and doing Visual C++

    Doesn't look like 2kaud specifically said, but if you want to see the results, you should be running the program from within a command window.
    If you're running it from within the IDE, which it looks like you are, then the command window will flash up and go away quickly enough you might not see it.
    When running from the IDE, you can put a user input as the last last like, i.e. a "Press any key to continue..." type thing so you can see the output of the program in the window, then hit a key to continue, which will close the window.

  6. #6
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    Try
    Code:
    	system("pause");
    before the closing } in main()
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7

    Thread Starter
    Member
    Join Date
    Oct 2014
    Location
    Canada, British Columbia
    Posts
    54

    Re: Learning and doing Visual C++

    Allrighty, thanks guys, that's a big help, oh, and 2kaud, i'd love it if you'd recommend some books for me. I know my dad used to own some, but they were all outdated, and gathering dust, so he threw them away, what a shame, i could've still learned from them.
    However, i have this book called Cocoa Programming for Mac OS X, and inside of it, it stated that it uses C# i believe, i was wondering if C# is similar to C++. and if the format of Mac programming could be re-used/re-formatted to suit Windows programming?
    Thanks
    Best Regards
    ~Mister_Meh
    ~Mister_Meh

  8. #8
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    Although c# has some basic similarities with c++, they are very different languages and in the main c# code is not c++ code. If you want to learn c++ then learn c++ and not try to understand c# code and convert to c++. I also would not try to use a book for Mac OS programming for Windows programming.

    The current version of c++ is c++14. This is a very recent version of c++ (it was only formally agreed earlier this year) and book authors by and large haven't caught up with it yet in their book versions. However, c++14 is only a minor revision of c++11 so any book which covers c++11 will be fine. The next major c++ revision is expected in 2017.

    Until you are quite familiar with c++ I would advise against any c++ book which does not cover c++11. This basically rules out any c++ book with a publishing date prior to 2012. There are several good books on advanced c++ programing published prior to this date which cover earlier versions of c++ (c++98 and c++03). Again I would caution against using these until you understand the basics of c++11. Avoid any book with a publication date prior to about 2004. These may seem tempting as they are available second hand very cheaply but the way you write code with c++11/14 is quite different to the way c++ code was written back then due to the way the language has evolved. IMO you should learn how to code 'modern c++' rather than how things were done over 10 years ago.

    c++ encompasses a large standard. This can briefly be broken into
    - 'c' part of c++ (basic statements, variables etc). This part of the language is very similar to the c language with some important differences
    - 'c' standard library (for dealing with c-style strings, cstyle i/o etc)
    - classes
    - exceptions
    - templates
    - standard template library (STL)
    - c++ i/o streams

    There are basically two schools of thought as to how c++ is taught. The 'old school of teaching' basically takes the view that you learn the 'c' part of c++ first and then learn the 'extras' to c such as classes, the STL etc as separate entities of c++ which are taught as separate parts.

    The 'modern' view of c++ teaching which c++ professional practitioners now say is the best way to teach c++ including the person who first developed the language - Bjarne Stroustrup (see his web site at http://www.stroustrup.com/ for further resources) - is to look at the c++ language 'in the whole' and teach all of its parts as a coherent whole.

    Many books that teach c++ are written from the 'old school' perspective and IMO I would avoid these - many even have 5 star reviews!

    For the books that teach c++ the 'modern' way I would suggest

    Programming: Principles and Practice Using c++ 2nd edition
    http://www.amazon.co.uk/Programming-...rds=stroustrup

    c++ Primer 5th edition
    http://www.amazon.co.uk/C-Primer-Sta...8122637&sr=1-1

    c++ How To Program (Early Object Version) 9th edition
    http://www.amazon.co.uk/How-Program-...1SWKVXR2TDP2QN


    Once you have some familiarity with c++ I would suggest
    Professional c++ 3rd edition
    http://www.amazon.co.uk/Professional...8122770&sr=1-1

    Effective Modern c++
    http://www.amazon.co.uk/gp/product/1...ilpage_o04_s00


    and the definitive c++ reference book (not one to teach c++)
    The c++ Programming Language 4th edition
    http://www.amazon.co.uk/C-Programmin...8122478&sr=1-3

    Good luck and happy programing
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9

    Thread Starter
    Member
    Join Date
    Oct 2014
    Location
    Canada, British Columbia
    Posts
    54

    Re: Learning and doing Visual C++

    Allright, i'll look into it. I appreciate your help
    Best Regards
    ~Mister_Meh
    ~Mister_Meh

  10. #10
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Learning and doing Visual C++

    Quote Originally Posted by Mister_Meh View Post
    However, i have this book called Cocoa Programming for Mac OS X, and inside of it, it stated that it uses C# i believe, i was wondering if C# is similar to C++. and if the format of Mac programming could be re-used/re-formatted to suit Windows programming?
    That book will be written in Objective C. (edit: OK, it might contain some English too.)
    C++, Objective C, and C# are three totally different languages. The only thing they share in common is a syntax derived from C (and in the case of Objective C, even that link is tenuous).

    If you haven't done C before, my recommendation would be to learn that first, before anything else.
    In my opinion object oriented languages cause more problems than they solve, though many would disagree.

  11. #11
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    If you haven't done C before, my recommendation would be to learn that first, before anything else.
    In my opinion object oriented languages cause more problems than they solve, though many would disagree.
    Yes, I disagree. if you are going to learn c++ then learn how to do things the c++ way - not the c way and then have to unlearn and re-learn. I've come across too many so-called 'c++ programmers' who still code as if they are writing c code with a few classes thrown in. If you don't want OO then by all means learn c but IMO treat c++ and c as different languages.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  12. #12
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Learning and doing Visual C++

    In my opinion object oriented languages cause more problems than they solve
    Like a lot of tools, it all depends upon how they are used and that the right tool is used for the required job. Like most things, using a wrong tool for a job can result in problems.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  13. #13

    Thread Starter
    Member
    Join Date
    Oct 2014
    Location
    Canada, British Columbia
    Posts
    54

    Re: Learning and doing Visual C++

    allright, so, i'll probably just focus on C++ then
    Thanks guys, you're a great help
    Best Regards
    ~Mister_Meh
    ~Mister_Meh

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width