• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:31
CEST 18:31
KST 01:31
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
BSL Team A vs Koreans - Sat-Sun 16:00 CET6Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80Weekly Cups (Sept 29-Oct 5): MaxPax triples up3PartinG joins SteamerZone, returns to SC2 competition32
StarCraft 2
General
The New Patch Killed Mech! TL.net Map Contest #21: Voting Revisiting the game after10 years and wow it's bad Stellar Fest: StarCraft II returns to Canada herO Talks: Poor Performance at EWC and more...
Tourneys
SC2's Safe House 2 - October 18 & 19 Sparkling Tuna Cup - Weekly Open Tournament $1,200 WardiTV October (Oct 21st-31st) WardiTV Mondays RSL Offline Finals Dates + Ticket Sales!
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers Mutation # 492 Get Out More
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ BW caster Sayle BSL Team A vs Koreans - Sat-Sun 16:00 CET BW General Discussion Question regarding recent ASL Bisu vs Larva game
Tourneys
[ASL20] Semifinal B [Megathread] Daily Proleagues SC4ALL $1,500 Open Bracket LAN [ASL20] Semifinal A
Strategy
Current Meta BW - ajfirecracker Strategy & Training Relatively freeroll strategies Siegecraft - a new perspective
Other Games
General Games
Stormgate/Frost Giant Megathread Dawn of War IV Path of Exile Nintendo Switch Thread ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Men's Fashion Thread Sex and weight loss
Fan Clubs
The herO Fan Club! The Happy Fan Club!
Media & Entertainment
Series you have seen recently... Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1515 users

The Big Programming Thread - Page 215

Forum Index > General Forum
Post a Reply
Prev 1 213 214 215 216 217 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
lonelyPotato
Profile Joined December 2012
Australia158 Posts
December 11 2012 10:11 GMT
#4281
On December 11 2012 19:07 Tobberoth wrote:
Show nested quote +
On December 11 2012 18:58 lonelyPotato wrote:
On December 11 2012 18:55 Tobberoth wrote:
On December 11 2012 18:53 lonelyPotato wrote:
On December 11 2012 18:50 tec27 wrote:
On December 11 2012 18:45 Tobberoth wrote:
On December 11 2012 18:31 Coal wrote:
Hello! I just started playing around with HTML for fun (I intend to learn how to create simpler websites one day), and I have a question. Since I just started, should I learn HTML or HTML 5? What are the differences between the two?


HTML5 and HTML is the same thing. HTML5 is just the most recent version of HTML, what you mean is probably HTML4 which is old. The differences are usually pretty minor, HTML5 just have some extra tags to work with. Obviously, there are huge differences in the background though.

You should definitely learn HTML5, everything else is outdated, including XHTML.

This. 100%.

lonelyPotato, please don't give advice about things you don't understand.

HTML5 does include some features/tags that aren't currently well supported in all browsers, but these are mostly extravagant things. For basic tags, all modern browsers will support them just fine. If you do get into learning about the more advanced stuff, this site: http://caniuse.com/ is really useful for figuring out which browsers support what.


I don't really know what I said wrong?

Basically, recommending someone to learn HTML4 over HTML5 is like telling someone who wants to learn photoshop that it's better to learn it using Photoshop CS3 over using CS5. It really makes no sense why you would want to learn using an old outdated version of something. It's not like HTML5 is more complicated, anything written in HTML4 can be rewritten to HTML5 and will look better in the process, such as the new Doctype etc.


True, you didn't have to say I didn't know what I was talking about though. I stated the difference between the languages and what I found different.

Honestly, HTML 4 elements were for me easier to use, and if you want to get a solid understanding of Web based programming you should have a solid understanding of both of the versions elements, especially since so many people still are using HTML 4.

I never said you didn't know what you were talking about, I agree with the person saying you gave bad advice though. I don't see how HTML4 elements can be easier to use, HTML5 uses the exact same elements, the only difference is that you can add in extra elements if you want, such as <section>, <header> and <footer>. If you have any idea how tags work, which you should obviously learn if you learn HTML, you realize that that these tags, all tags, are extremely simple. Outside of CSS usage, it's just basic semantics. "I want my email in the footer of the website, maybe I should add it in a <footer> element at the bottom so I can later style it". Perfect. You can put it in a div in HTML4 for the same reason if you find that simpler for some reason, but nothing stops you from doing that in HTML5 if the <footer> tag scares you.

As for a lot of people using HTML4, that's true. A lot of people still use outdated versions of Internet Explorer. Just because other people are dumb and ignorant doesn't mean it's a good idea to go that route yourself.


It's nothing to do with being dumb, it's to do with cost and minimizing web disruptions. I won't put it up at the level of IPv6 in terms of disruptions, but it's partially a similar reason why people won't switch to that.

They go by the theory, why fix something that aint broke.
Tobberoth
Profile Joined August 2010
Sweden6375 Posts
December 11 2012 10:15 GMT
#4282
On December 11 2012 19:11 lonelyPotato wrote:
Show nested quote +
On December 11 2012 19:07 Tobberoth wrote:
On December 11 2012 18:58 lonelyPotato wrote:
On December 11 2012 18:55 Tobberoth wrote:
On December 11 2012 18:53 lonelyPotato wrote:
On December 11 2012 18:50 tec27 wrote:
On December 11 2012 18:45 Tobberoth wrote:
On December 11 2012 18:31 Coal wrote:
Hello! I just started playing around with HTML for fun (I intend to learn how to create simpler websites one day), and I have a question. Since I just started, should I learn HTML or HTML 5? What are the differences between the two?


HTML5 and HTML is the same thing. HTML5 is just the most recent version of HTML, what you mean is probably HTML4 which is old. The differences are usually pretty minor, HTML5 just have some extra tags to work with. Obviously, there are huge differences in the background though.

You should definitely learn HTML5, everything else is outdated, including XHTML.

This. 100%.

lonelyPotato, please don't give advice about things you don't understand.

HTML5 does include some features/tags that aren't currently well supported in all browsers, but these are mostly extravagant things. For basic tags, all modern browsers will support them just fine. If you do get into learning about the more advanced stuff, this site: http://caniuse.com/ is really useful for figuring out which browsers support what.


I don't really know what I said wrong?

Basically, recommending someone to learn HTML4 over HTML5 is like telling someone who wants to learn photoshop that it's better to learn it using Photoshop CS3 over using CS5. It really makes no sense why you would want to learn using an old outdated version of something. It's not like HTML5 is more complicated, anything written in HTML4 can be rewritten to HTML5 and will look better in the process, such as the new Doctype etc.


True, you didn't have to say I didn't know what I was talking about though. I stated the difference between the languages and what I found different.

Honestly, HTML 4 elements were for me easier to use, and if you want to get a solid understanding of Web based programming you should have a solid understanding of both of the versions elements, especially since so many people still are using HTML 4.

I never said you didn't know what you were talking about, I agree with the person saying you gave bad advice though. I don't see how HTML4 elements can be easier to use, HTML5 uses the exact same elements, the only difference is that you can add in extra elements if you want, such as <section>, <header> and <footer>. If you have any idea how tags work, which you should obviously learn if you learn HTML, you realize that that these tags, all tags, are extremely simple. Outside of CSS usage, it's just basic semantics. "I want my email in the footer of the website, maybe I should add it in a <footer> element at the bottom so I can later style it". Perfect. You can put it in a div in HTML4 for the same reason if you find that simpler for some reason, but nothing stops you from doing that in HTML5 if the <footer> tag scares you.

As for a lot of people using HTML4, that's true. A lot of people still use outdated versions of Internet Explorer. Just because other people are dumb and ignorant doesn't mean it's a good idea to go that route yourself.


It's nothing to do with being dumb, it's to do with cost and minimizing web disruptions. I won't put it up at the level of IPv6 in terms of disruptions, but it's partially a similar reason why people won't switch to that.

They go by the theory, why fix something that aint broke.

It's one thing not to fix something old which works, and another to build something new in something old when a superior new version exists. If you have a 5 year old complex webpage using HTML4, you're obviously not going to force a rewrite to HTML5, I sure as hell don't do it at my job. If you're LEARNING HTML though, there's literally no reason what so ever to learn HTML4 over HTML5. Especially since you'll have no problem working with old HTML4 pages just because you happen to know HTML5.
lonelyPotato
Profile Joined December 2012
Australia158 Posts
December 11 2012 10:16 GMT
#4283
On December 11 2012 19:08 AmericanUmlaut wrote:
Show nested quote +
On December 11 2012 19:00 lonelyPotato wrote:
On December 11 2012 18:56 AmericanUmlaut wrote:
On December 11 2012 18:43 lonelyPotato wrote:
On December 11 2012 18:31 Coal wrote:
Hello! I just started playing around with HTML for fun (I intend to learn how to create simpler websites one day), and I have a question. Since I just started, should I learn HTML or HTML 5? What are the differences between the two?



HTML 5 offers better error handling (Corporations used to have to reverse engineer through HTML 4 code, that's not as much of an issue any more), better defined semantics (Basically means your code becomes a lot more organized), and also has lots of small little added features that allow for a more dynamic feel to your website rather than having to use little third party programs to do so.

I am not a professional with HTML, but I have done a course for it at university, and personally I find HTML4 easier to use than HTML 5. So for a learning platform, I would learn HTML 4 first, and if you like what you see, you can make the jump to HTML 5 with ease if you have a solid understanding of HTML 4.

If you want more information then don't be afraid to ask.

Almost nothing you said in this post is accurate or useful.


Wait are you serious! HTML doesn't offer better defined semantics? Are you really saying that is wrong?

Are you saying that HTML 4 Wasn't retardedly hard to reverse engineer relative to that of HTML 5?

Are you saying that HTML 5 doesn't offer a more dynamic feel without having to access third party programs?

How is any of what I said wrong?

How does HTML 5 offer better error handling? HTML is a markup language: it has no error handling.

What do you mean by "reverse engineering"? You don't have to reverse engineer anything in HTML. Reverse engineering means looking at a result and then creating a system to generate that result, that doesn't even make sense as something that you would do in the context of HTML, which is served in plain text - if you want to know how a result is generated, you read the served markup.

How is HTML4 "easier to use" than HTML5? HTML5 is basically a superset of HTML4, so you're saying it's easier to learn a subset of a language's features, but that's self-evident, and the way you write it implies that writing markup to generate a result in HTML4 is simpler than writing markup to generate the same result in HTML5, which is absurd because HTML4 markup works in an HTML5-compliant browser.

Edited: For niceness and grammar.

Also: I do agree that HTML5's additional tags make markup more semantic.


I was referring to the new Parsing/Compatibility rules when it comes to error handling.
Kiante
Profile Blog Joined December 2009
Australia7069 Posts
December 11 2012 10:38 GMT
#4284
Hey lonelypotato do you live in brisbane>?
Writer
lonelyPotato
Profile Joined December 2012
Australia158 Posts
December 11 2012 10:58 GMT
#4285
On December 11 2012 19:38 Kiante wrote:
Hey lonelypotato do you live in brisbane>?


Nah Adelaide.
Coal
Profile Joined July 2011
Sweden1535 Posts
December 11 2012 11:05 GMT
#4286
Thank you for all the answers! I'm sure lonelypotato meant no harm I'll check in later if I have any questions!
In order to succeed, your desire for success should be greater than your fear of failure.
carlfish
Profile Joined June 2011
Australia57 Posts
Last Edited: 2012-12-11 11:44:40
December 11 2012 11:42 GMT
#4287
On December 11 2012 19:08 AmericanUmlaut wrote:
How does HTML 5 offer better error handling? HTML is a markup language: it has no error handling.


One of the practical problems with HTML4 was that it did not provide a clear definition of what a user-agent should do when it encountered bad markup.

Ideally this wouldn't be a problem because all markup would be valid, but in the real world "tag soup" is the norm. When a browser encountered something broken like <i><b>hello</i></b>, the behaviour would be undefined. Most browsers would internally convert the above into _some_ kind of valid DOM so the markup could be displayed in the browser, but there as no guarantee that each browser would produce the same DOM.

This would cause problems because CSS and Javascript rely on DOM selectors to function, and if two browsers are producing different internal DOMs for the same (invalid) markup, then that would mean the webpage would display differently in different browsers. A bad thing. You could argue until you were blue in the face that web authors should just fix their markup, but the practical result for the browser vendor was that end-users would complain that their browser "didn't show pages properly" compared to whatever browser the site had been developed for.

Often, browsers would waste a lot of time trying to reverse-engineer what other browsers were doing with bad markup in an effort to remain bug-for-bug compatible and thus display real-world web pages in the same way as their more popular competitors.

HTML5 recognised this problem, and the spec goes to great lengths to define what browsers should do when they encounter bad markup, and especially what they should do while parsing to turn bad markup into good, predictable DOM.
I am a fish.
mcc
Profile Joined October 2010
Czech Republic4646 Posts
December 11 2012 12:11 GMT
#4288
On December 11 2012 17:56 Poopi wrote:
Thanks for the info guys. I will definitively use it if I ever put something on the internet using PHP/MySQL, however I forgot to precise that it was a school project which I send in .zip and will be tested in local. Thus protecting properly isn't really necessary since well, the only person who will see this will have access to every file anyways.

However we were told about security, but only about mysql_real_escape_string so I did use it even though in this case it's pointless we had to do this at least.

By the way for these type of SQL injects, the "malicious" user (lol) has to know or guess your table names, hasn't he?

You should still make it a habit to use parameters anyway. Good habits are half of programming Plus it actually should make the queries more effective.
AmericanUmlaut
Profile Blog Joined November 2010
Germany2579 Posts
December 11 2012 12:35 GMT
#4289
On December 11 2012 20:42 carlfish wrote:
Show nested quote +
On December 11 2012 19:08 AmericanUmlaut wrote:
How does HTML 5 offer better error handling? HTML is a markup language: it has no error handling.


One of the practical problems with HTML4 was that it did not provide a clear definition of what a user-agent should do when it encountered bad markup.

Ideally this wouldn't be a problem because all markup would be valid, but in the real world "tag soup" is the norm. When a browser encountered something broken like <i><b>hello</i></b>, the behaviour would be undefined. Most browsers would internally convert the above into _some_ kind of valid DOM so the markup could be displayed in the browser, but there as no guarantee that each browser would produce the same DOM.

This would cause problems because CSS and Javascript rely on DOM selectors to function, and if two browsers are producing different internal DOMs for the same (invalid) markup, then that would mean the webpage would display differently in different browsers. A bad thing. You could argue until you were blue in the face that web authors should just fix their markup, but the practical result for the browser vendor was that end-users would complain that their browser "didn't show pages properly" compared to whatever browser the site had been developed for.

Often, browsers would waste a lot of time trying to reverse-engineer what other browsers were doing with bad markup in an effort to remain bug-for-bug compatible and thus display real-world web pages in the same way as their more popular competitors.

HTML5 recognised this problem, and the spec goes to great lengths to define what browsers should do when they encounter bad markup, and especially what they should do while parsing to turn bad markup into good, predictable DOM.

That's true, but it's a user-agent feature, not an aspect of the language itself. It makes the lives of browser developers better, because they don't have to figure out what the de facto industry standard is for being liberal in accepting mangled markup, but it basically has no impact on a developer. It just means that your mangled markup, whether you were trying to write HTML4 or HTML5, will look more consistent across browsers.
The frumious Bandersnatch
3FFA
Profile Blog Joined February 2010
United States3931 Posts
Last Edited: 2012-12-11 21:43:59
December 11 2012 21:35 GMT
#4290
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

Some things my teacher loves to give us is questions that have us:
1) Correct a program and/or rewrite it
2) Find what 1 error is in a program
3) Find what the purpose of the program is (Example is that one she gave us and asked this question just skipped lines...)
4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-12-11 23:14:31
December 11 2012 21:49 GMT
#4291
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

Some things my teacher loves to give us is questions that have us:
1) Correct a program and/or rewrite it
2) Find what 1 error is in a program
3) Find what the purpose of the program is (Example is that one she gave us and asked this question just skipped lines...)
4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)



1 and 2 are the same.

I'm just going to point out a common error question, semi-colons after a loop conditional, such as.
int i = 0;
for ( i = 0; i < n; i++ );
printf("%d",i);

versus
int i = 0;
for ( i = 0; i < n; i++ )
printf("%d",i);


Finding errors should really be fun on tests. Not so in real life.

You will need to differentiate between syntactic and semantic errors.

3. Purpose should be easily found by tracing, if you understand the code. It helps to write out what they're doing by hand. Verify you understand how <= versus < affects a condition.

The output of
int i = 0;
while ( i <= 10 ) i = i + 1;


is different from
int i = 0;
while ( i < 10 ) i = i + 1;


4. I think you mean factors? There's only 1 factorial of 10. These questions should just require rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.
There is no one like you in the universe.
3FFA
Profile Blog Joined February 2010
United States3931 Posts
December 11 2012 22:33 GMT
#4292
Ok thanks! That was better than I was expecting! This forum never fails to surprise me, and this thread never fails to impress me.
"As long as it comes from a pure place and from a honest place, you know, you can write whatever you want."
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 11 2012 23:22 GMT
#4293
On December 12 2012 06:49 Blisse wrote:
+ Show Spoiler +
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

Some things my teacher loves to give us is questions that have us:
1) Correct a program and/or rewrite it
2) Find what 1 error is in a program
3) Find what the purpose of the program is (Example is that one she gave us and asked this question just skipped lines...)
4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)


1 and 2 are the same.

I'm just going to point out a common error question, semi-colons after a loop conditional, such as.
int i = 0;
for ( i = 0; i < n; i++ );
printf("%d",i);

versus
int i = 0;
for ( i = 0; i < n; i++ )
printf("%d",i);


Finding errors should fun on tests.

You need to differentiate between syntactic and semantic errors.

3. Purpose should be easily found by tracing, if you understand the code. It helps to write out stuff by hand. Verify you understand how <= versus < affects a condition.

The output of
int i = 0;
while ( i <= 10 ) i = i + 1;


is different from
int i = 0;
while ( i < 10 ) i = i + 1;


4. I think you mean factors? There's only 1 factorial of 10. That should just be rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.


Love this specific advice, bolded parts I think are worth stressing (I won't write too much more on this, since Blisse nailed it).
No one can tell you the best way for you to study or practice something. There isn't any secret towards practice, except to do something, and to enjoy doing something enough that you want to come back to it later.

It's ok for programming to make you feel frustrated. That's a sign that your brain is actively trying to figure something out, and it may never go away, as the problems you encounter when programming just get larger an more difficult to handle. What you should avoid is feeling bored. If you are feeling bored during studying, then go find a different way to study.

Here's some tunes to study to:
echo "main(i){for(i=0;;i++)putchar(((i*(i>>8|i>>9)&46&i>>8))^(i&i>>13|i>>6));}" | gcc -x c - && ./a.out | aplay
Any sufficiently advanced technology is indistinguishable from magic
magicmUnky
Profile Joined June 2011
Australia280 Posts
December 12 2012 00:14 GMT
#4294
I think he meant 1!, 2!, 3!, ... , 10!

1
2
6
24
etc etc

I'm working through a C++ book and another for writing for embedded systems... lots of fun! Someone on here advised me to purchase "C++ Primer 5th Ed - Lippman, Lajole, Moo" and I'm finding it really handy.. it's much more explanatory than my other books (Programming C, Matlab and Java for Engineers).

One thing I can't really wrap my head around is; why does cin use >> and cout use <<?

I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing
thOr6136
Profile Blog Joined July 2009
Slovenia1775 Posts
December 12 2012 00:19 GMT
#4295
Yo guys i need your help!

So, basically lets say we have 2D array, for example height = 7 and width = 7. Next i choose an element in this array, lets say [2][3]. My task is to go to every element that is in horizontal, vertical and diagonal line and do something with it. Now here is my question, is there any other more efficient, less time-consuming way to go through these elements other then making basically 8 loops (one for up, down, left right, up-left, up-right... etc.)?
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
Last Edited: 2012-12-12 00:38:19
December 12 2012 00:36 GMT
#4296
On December 12 2012 09:14 magicmUnky wrote:
I think he meant 1!, 2!, 3!, ... , 10!

1
2
6
24
etc etc

I'm working through a C++ book and another for writing for embedded systems... lots of fun! Someone on here advised me to purchase "C++ Primer 5th Ed - Lippman, Lajole, Moo" and I'm finding it really handy.. it's much more explanatory than my other books (Programming C, Matlab and Java for Engineers).

One thing I can't really wrap my head around is; why does cin use >> and cout use <<?

I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing


Oof, let's start with the lingo. C++ uses these operators as 'stream operators'. The '<<' version is an 'insertion operator'. Putting some bits into a 'stream' can be rather confusing on the low level side of things, so C++ uses this operator with output streams to format the stream to the right, and make a call to sprint(STD_OUT,"**formatted stuff**"), which will push the bits through to the standard out stream (usually your terminal, for embedded projects, its normally the UART0 or SPI port, depending on the board/libraries you are using).

the '>>' operator is used as the 'extraction operator', which then pulls bits off the stream (when they are available) and formats it to fit the right side.

They are both 'overloaded operators' brought in from the <iostream.h> library to make streams easier to use. Overloading an operator just means defining it to use it for a different set of types. For example, you could overload '+' to work for a Vector class (Vector::operator+), then in the definition, make it so when you add two vectors, Vector A and Vector B, it does it the intuitive way.

EDIT: also, cout and cin are referred to as 'streams', which really just means its a file descriptor. Network sockets are streams as well. There are other streams too, but the definition is different system to system.
Any sufficiently advanced technology is indistinguishable from magic
HaRuHi
Profile Blog Joined November 2010
1220 Posts
December 12 2012 00:44 GMT
#4297
On December 12 2012 09:14 magicmUnky wrote:
I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing


The Idea behind designing it like this was:

cin is a stream,
an input stream.
a stream flows,
with "cin>>var1" ,cin flows into var1.

cout aswell is a stream,
with "cout<<var1",
var1 flows into the outputstream.

Donnu if that is helpful for remembering when to why use what^^.
RoyGBiv_13
Profile Blog Joined August 2010
United States1275 Posts
December 12 2012 00:59 GMT
#4298
On December 12 2012 09:19 thOr6136 wrote:
Yo guys i need your help!

So, basically lets say we have 2D array, for example height = 7 and width = 7. Next i choose an element in this array, lets say [2][3]. My task is to go to every element that is in horizontal, vertical and diagonal line and do something with it. Now here is my question, is there any other more efficient, less time-consuming way to go through these elements other then making basically 8 loops (one for up, down, left right, up-left, up-right... etc.)?


psuedocode, assuming a square matrix, deal with it:

Given you start at X,Y ---
for(i:0->MATRIX WIDTH)
{
matrix[Y][i] //horizontal row
matrix[i][X] //vertical column
matrix[Y+i][X+i] //down and to the right
matrix[Y-i][X+i] //up and to the right
matrix[Y+i][X-i] //down and to the left
matrix[Y-i][X+i] //up and to the left
}


Left intentionally unoptimized. This should give you the right idea of how to traverse matrices.

For a bit of math to get you started, you will need a maximum of 2 for loops to do most matrix problems. If you can find no other way, traverse the entire matrix, and check if the spot you are at is the one you are looking for using your math equations you calculated:


for(i:0->MAX_X)
for(j:0->MAX_Y)
if(j==Y) //horizontal row
if(X+i==Y+j) //diagonal
and so on..


The single for loop example above is a reduction of this complete case
Any sufficiently advanced technology is indistinguishable from magic
adwodon
Profile Blog Joined September 2010
United Kingdom592 Posts
December 12 2012 09:31 GMT
#4299
On December 12 2012 06:49 Blisse wrote:
Show nested quote +
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)



4. I think you mean factors? There's only 1 factorial of 10. These questions should just require rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.


http://projecteuler.net/ is great for those relatively quick, self contained programming problems.

Some are really tricky and may take a little while but they're all perfectly doable by 1 person at a reasonable pace, try doing one or two a week and you'll really improve. It's also a good way to learn new languages, trying to redo old problems in a new language can help you get a grip on it a bit better.
Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2012-12-12 16:14:45
December 12 2012 15:59 GMT
#4300
On December 12 2012 18:31 adwodon wrote:
Show nested quote +
On December 12 2012 06:49 Blisse wrote:
On December 12 2012 06:35 3FFA wrote:
First of all, thanks again guys! You are a great help

I would like some practice with my (Not objective or ++!)C loops(for, dowhile, while, and nested loops) before a test my teacher is giving soon. Any sites that are good for this?

4) Write short programs, fulfilling certain credentials. (Example: Write a for loop that displays the factorials of 10)



4. I think you mean factors? There's only 1 factorial of 10. These questions should just require rudimentary math knowledge. Try doing things like the Fibonacci sequence, FizzBuzz, or the 1000 Lockers problem with your computer. (Google)

Practice coding anything. That is literally all the heck you have to do to study a problem solving programming course.

http://www.reddit.com/r/dailyprogrammer/

will help get your started becoming confident in your programming skills. The current day's question tests file input and string comparison among other things. If you don't understand file input, you should understand and use stream redirection.

Otherwise, revisit your old assignment questions and rewrite them with different numbers or input, and make them better using what you know now.

Also, if it's not online, practice coding by hand.


http://projecteuler.net/ is great for those relatively quick, self contained programming problems.

Some are really tricky and may take a little while but they're all perfectly doable by 1 person at a reasonable pace, try doing one or two a week and you'll really improve. It's also a good way to learn new languages, trying to redo old problems in a new language can help you get a grip on it a bit better.


I'm less a fan of Project Euler because it only focuses on mathematical problem solving. DailyProgrammer puts out a mix of mathematical problem solving, and also other stuff like string manipulation and fun things like Pokemon type comparisons, which can involve a lot more than just hard coding some numbers together.


On December 12 2012 09:14 magicmUnky wrote:
I think he meant 1!, 2!, 3!, ... , 10!

1
2
6
24
etc etc

I'm working through a C++ book and another for writing for embedded systems... lots of fun! Someone on here advised me to purchase "C++ Primer 5th Ed - Lippman, Lajole, Moo" and I'm finding it really handy.. it's much more explanatory than my other books (Programming C, Matlab and Java for Engineers).

One thing I can't really wrap my head around is; why does cin use >> and cout use <<?

I know i can do things like std::cin >> var1 >> var2;
but why does cout demand <<? The book says it's because the cin command takes it's right operator as the statement but cout takes it's left hand operand or something along those lines.. confusing



>> is an extraction operator. http://www.cplusplus.com/reference/istream/istream/operator>>/

<< is an insertion operator. http://www.cplusplus.com/reference/ostream/ostream/operator<</

What does that mean?

When you do,

std::cin >> var;


you are performing an extraction out of the std::cin stream, which is your standard input.

When you do,

std::cout << word << std::endl;


you are performing an insertion of your word into the std::cout stream, which is your standard output.


Why don't they combine the two? Because overloading functions like you want would confuse meaning of the words. It is much more clear to see in the

std::cin >> var;
std::cout << word << std::endl;


case, that the values from the stream std::cin are extracted into the value var, and the word is being inserted into the stream std::cout.

var << std::cin;
std::cout << var;


would look very strange, because now it's not clear what you're doing exactly. You overload the meaning of << as both an insertion operation and an extraction operation. However, it doesn't make sense to do that because the two operations are not associative. The + operator is associative in the sense that 1 + 2 == 2 + 1. It's an operation of add regardless. However, std::cin << word != word << std::cin, because they're both not insertion operations.

The << and >> separate the meaning of insertion and extraction.

I hope that makes some sense. I didn't design the language, but this is what seems to make sense for me.
There is no one like you in the universe.
Prev 1 213 214 215 216 217 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 29m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
LamboSC2 492
ProTech79
BRAT_OK 56
MindelVK 20
StarCraft: Brood War
Soma 1529
Horang2 1474
Light 830
ZerO 751
Barracks 697
Larva 685
Mini 589
Stork 448
actioN 423
firebathero 312
[ Show more ]
hero 273
Hyun 262
JulyZerg 172
PianO 123
ggaemo 114
Rush 93
sorry 70
Pusan 66
Dewaltoss 63
Mong 62
Sharp 52
zelot 49
ToSsGirL 23
Sacsri 21
Terrorterran 18
scan(afreeca) 11
NaDa 11
ajuk12(nOOB) 8
Dota 2
Gorgc8460
qojqva2660
Fuzer 321
Counter-Strike
olofmeister1983
fl0m1797
Heroes of the Storm
Khaldor607
Liquid`Hasu371
Other Games
singsing2117
B2W.Neo1197
Skadoodle302
Hui .244
ArmadaUGS169
KnowMe160
ZerO(Twitch)34
Trikslyr30
Organizations
Other Games
BasetradeTV26
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• HeavenSC 28
• Adnapsc2 23
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• HerbMon 9
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• C_a_k_e 3590
• lizZardDota241
League of Legends
• Jankos3420
Upcoming Events
Safe House 2
29m
IPSL
2h 29m
Sziky vs Havi
Artosis vs Klauso
Monday Night Weeklies
23h 29m
WardiTV Invitational
1d 18h
WardiTV Invitational
1d 21h
Tenacious Turtle Tussle
3 days
The PondCast
3 days
WardiTV Invitational
4 days
Online Event
4 days
RSL Revival
5 days
[ Show More ]
RSL Revival
5 days
WardiTV Invitational
5 days
Afreeca Starleague
6 days
Snow vs Soma
Sparkling Tuna Cup
6 days
WardiTV Invitational
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.