I think both the C++ variants need to include '<< std::endl' or '<< "\n"' :-)
Announcement
Collapse
No announcement yet.
Google Wants To Make C++ More Fun
Collapse
X
-
Originally posted by BlackStar View PostI mean something like this:
Code:#include <iostream> #include <boost/lexical_cast.hpp> int main(int argc, char *argv[]) { std::cout << boost::lexical_cast<std::string>(42); return 0; }
Code:10 PRINT 42
As for BASIC, IIRC it has PEEK and POKE that do direct memory manipulation though not as versatile as pointers. Which language is more high level now?
More importantly, some people take "high level" to mean more powerful and capable of more subtle control of a computer; others take high level to mean more abstracted from the hardware.
By the first definition, C++ is more high level than BASIC, by the second definiton BASIC is more high level (and your average scripting language like python or perl even more so).
So, what do you mean by high level? I still think you and your other correspondent are arguing English semantics.
Comment
-
More importantly, some people take "high level" to mean more powerful and capable of more subtle control of a computer; others take high level to mean more abstracted from the hardware.
Originally posted by hoohoo View PostI think you are picking your language features carefully, Blackstar. As Drago pointed out that lexical cast is unneeded because cout can handle all the elementary types already.
Comment
-
Originally posted by hoohoo View PostMore importantly, some people take "high level" to mean more powerful and capable of more subtle control of a computer; others take high level to mean more abstracted from the hardware.
By the first definition, C++ is more high level than BASIC, by the second definiton BASIC is more high level (and your average scripting language like python or perl even more so).
So, what do you mean by high level? I still think you and your other correspondent are arguing English semantics.
Originally posted by BlackStar View PostIrrelevant. "High-level" is a well defined term, even if some people confuse it with "powerful". Those people should open a textbook.
The problem is that human language does not match that of the hardware and hence, while "high-level" languages are easier for humans to use, they are very inefficient translators.
On contrary, "low-level" language is very close to that of hardware and it results in opposite effects.
So hoohoo is correct.
Your example, BlackStar is incomplete. Because the
PRINT 42
construction basically expands to that of C++ equivalent in logic, although never directly ofc. What you are loosing here, is the control over relevant parts.
C/C++ was designed to offer both of the worlds, being both powerful by staying close to hardware language (no relevant parts missed), yet being much easier to understand by humans than assembler.
This is why many refer to C as "middle level" language.
---
But, because all three language levels are only logic abstractions between machine and programmer, they offer various balances between flexibility and difficulty. They will be translated into machine language anyway, this is why "what is better" is wrong question.
"What is better WHEN" is correct question. "WHEN" at this level is expanded to circumstances, conditions, awaited result.
You are basically comparing mice to elephants, one claims elephants are stronger, other claims mice are more flexible.
Don't do that, this is silly.
Well elephant can't pass into the hole; mice cannot lift trees.
Use right tool for the job. There is no "better" here.
Originally posted by BlackStar View PostIndeed, I picked my "hello world" example very carefully.
Originally posted by strcat View PostI know it was a joke, but using std::endl is the exact same thing as '\n', except it also flushes the stream.Last edited by crazycheese; 21 June 2012, 11:01 PM.
Comment
-
Originally posted by crazycheese View PostI think the idea to include "endl" was to improve portability by replacing system-specific constants (such as '\n') by a much more flexible automatic. Also, '\n' in this context applies to streams and as such it justifies its existence.
Comment
-
Originally posted by allquixotic View Posthttp://www.paulgraham.com/avg.html
You are all wrong
Using this articles own words, if you need recursive programming, you don't use BASIC. And thats ok.
Thanks for the article.
Originally posted by strcat View PostIt's a very common misconception that endl is somehow more portable than '\n'. Both of them will use the system-specific newline representation, but endl also flushes the stream (which is sometimes but not always desirable, and stream.flush() also works).
Comment
-
Originally posted by crazycheese View PostI don't believe it to be "common misconception", because from my point of view, it is better to "endl" than to work on this one. Please prove me wrong.
Many C++ books contain example code like this... std::cout << "Test line" << std::endl; ...so I've always done that too. But I've seen a lot of code from working developers like this
(or the C++ standard, which also confirms this)Last edited by strcat; 22 June 2012, 03:26 AM.
Comment
Comment