开发者

New to C++, need useful examples [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I am new to Stack Overflow, and new to programming. I am learning how to program in C++.

My question is not related to specific code, but is about research and learning the language. What I have learned so far relates to narrow examples of syntax and simple programs which use variables, functions, arrays, etc.

I am wondering if people have or can link to example programs so I can study them.

I'm looking for console programs which:

  • use variables (int, double, string, etc)
  • use functions
  • use arrays use classes with
  • attributes and methods use objects of that class
  • reads and writes to a file
  • validates user inputs, displaying appropriate error messages

and is basically a useful program.

Through Google, I have mostly only been able to find C++ tutorial pages (cplusplus, cprogramming, etc) which deal with each of the above separately, usually in开发者_运维百科 a bare-bones way to show the syntax. I'm looking for something more complex (but not overly so) so I can learn how to combine these things in a meaningful way with the intent of eventually writing programs of my own at the same level.

I've already coded a calculator (though not one that has all of these features; namely it was missing file i/o and I was able to make a basic one which didn't need objects), so I'm looking for something different. I understand console programs are text based and lend themselves well to these kind of programs, so it can be a calculator of another type, as long as it isn't a basic arithmetic one.


People here won't teach you C++. In fact, even a book or Google by themselves won't exactly teach you any language, they are just tools to make your life easier and the studying curve smoother.

My suggestion is to use Google or a good C++ book and write code.. especially write code, otherwise you won't learn anything, you must get your hands dirty in order to learn C++.


cplusplus.com has a few examples.


As @GMan said, you'd be better off reading a book.

Possibly Effective C++ by Scott Meyers, or maybe one in the Beginner\Introductory section.


The best way to improve is to give yourself a task and code it. Use different techniques/paradigms (OOP, modular, etc). Instead of studying programs, try to create them yourself - you'll learn a lot better this way.

The book can guide you, but you must make the journey.


Here are some exercises. You can try solving puzzles, too. CodeGolf.SE is good if you want to have some fun.


I hope you've got an excellent book. :)

That said, I understand the desire to find source code you can read that's larger than toys, but not giant cathedrals of code; perhaps the AppArmor policy parser can be of service to you. It's a little bit involved, because it's a small-language compiler that builds a DFA of a security policy for 'execution' in the kernel when confined programs perform file operations.

You can clone it with bzr: http://bazaar.launchpad.net/~apparmor-dev/apparmor/master/ or you can browse the source code: http://bazaar.launchpad.net/~apparmor-dev/apparmor/master/files/head:/parser/libapparmor_re/


Supplementing the other posts directing you to various reading, if you are new to programming, I highly recommend starting your venture into programming with Python.

Python is an easy-to-learn programming language that has a LOT built-in and will allow you to start making useful "programs" very quickly.

For example, you can read the entire contents of a text file with a single line of code:

file_contents = open('example.txt','r').read()

I feel it keeps people more encouraged when they can see significant results as they learn. If you are interested, Dive Into Python is a very popular tutorial.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜