Thursday, July 30, 2009

I need understanding some of the basics of C++?

hey guys, I am trying my best to learn and understand c++ but I have come across a wall. I have a simple question.





1. I do not understand what the setw( ) manipulator does. Let's say in your code you have a line saying...





cout %26lt;%26lt;"Start" %26lt;%26lt; setw(4) %26lt;%26lt; 10 %26lt;%26lt; setw(4) %26lt;%26lt; 20%26lt;%26lt; setw(6) %26lt;%26lt; 30;





This would output something like





Start 10 20 30





In my book it says that there are two spaces before the 10, two spaces before the 20, and four spaces before the 30... but I thought setw(4) meant put 4 spaces between 10 and 20. I need some clarifying.

I need understanding some of the basics of C++?
setw() sets the width of the display field. Thus





setw(4) %26lt;%26lt; 10





is an expression that puts the number 10 in a display field 4 wide.





The %26lt;iomanip%26gt; headers must be included.
Reply:Paul Lutus posted that entire book online about 10 years ago, it is still available.


http://www.arachnoid.com/cpptutor/index....


There are about 20 pages, but is written to be understood.


http://www.arachnoid.com/cpptutor/intro....


On Windows, well pay to play os, or rent to never own.


http://www.arachnoid.com/cpptutor/setup_...


Get a GOOD Linux distro and learn all you want.


http://vps.arachnoid.com/careware/


Even though this page has a big, impressive title, it is about a simple idea which I hope I can convey in a few words. Here are the main points:





* Economic principles lie behind many more human activities than most of us realize. We are almost constantly exchanging something for something else.


* Many economic transactions don't involve money. In traditional societies, and sometimes even this one, people trade using favors, influence, even pure ideas, instead of money.


* Sometimes money is not the best way to convey value. And sometimes money is so completely inappropriate that it destroys the transaction . CareWare is one of those transactions.


* CareWare * doesn't involve money, but it is a transaction nevertheless. Something is delivered, something is received. Adam Smith's invisible economic hand moves through the CareWare economy just like everywhere else. I can't ask for something more than I am giving, but I can ask for an appropriate exchange.





In CareWare, * the "buyer" gets something of value in exchange for something the "seller" wants. And what does the seller want? The general answer is "Anything except money," but I prefer the really remarkable transactions, which you recognize instinctively when you see them.





Here is an example — here is a hypothetical transaction between myself and you. I have a program called "Arachnophilia" which is a rather nice Web page editor and workshop, but I don't want your money in exchange, I want something else. So I say "This is what I am offering, and here is what I want in return." Simple, right? I have been doing this for a little while now, and the responses have been very interesting. Many people think I have religious beliefs — I don't, at least not religious beliefs recognizable by a person of normal intellectual gifts. Others try to push the transaction in a more traditional direction for one reason or another — I recently received this message:








Careware,eh? A small price to pay for such a


great software package. My pen quivers over my


checkbook in case you change your mind.








This response could arise from any number of causes, and bartering about the medium as well as the size of the payment is a normal part of economic transactions, so maybe I am picking on this particular correspondent a little. But the funny part is CareWare is by no means a small price to pay .





For example, here is a payment I will accept for a copy of Arachnophilia --





To own Arachnophilia, I ask that you stop whining about how hard your life is, at least for a while. When Americans whine, nearly everybody else in the world laughs. We have so much, and yet we manage to:





* Overlook great examples of beauty around us,


* Miss our most important opportunities,


* Manage to make ourselves miserable by expecting something even better to come along.





Every time we whine about how tough we have it, apart from the fact that we look ridiculous, we make it harder for people around us to appreciate how much we have. We encourage people to overlook the things we do have, the gifts of man and nature. We provide a context to dismiss everything as not good enough, to be miserable in the midst of plenty.





Don't get the wrong impression — many things are unjust, things that should be struggled against until they are made right. This page is for people who can't find even one thing to take joy in, to appreciate. These people not only make themselves miserable, but they infect others with the attitude that the world should right itself, by itself, before they will take simple pleasure in anything.





So here is my deal: stop whining for an hour, a day, a week, your choice, and you will have earned your copy of Arachnophilia. Say encouraging words to young people, make them feel welcome on the planet Earth (many do not). Show by example that we don't need all we have in order to be happy and productive.





Paul Lutus, Port Hadlock, Washington





Also see Interview With an Extraterrestrial on this topic.





Important Note: if you don't like this idea, just ignore it — you can have Arachnophilia anyway. That's one way to distinguish the world of ideas from the rest of human history: you can disregard an idea and no one knocks on your door at midnight.





Please feel free to make a link to this page — example:


%26lt;A HREF="http://www.arachnoid.com/careware"...


Download this article in Word 7.0 format Download this article in RTF format


Main Page


Have Fun and share the knowledge


No comments:

Post a Comment