[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
There was a programming thread earlier, so I figured I'd
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /r9k/ - ROBOT9001

Thread replies: 57
Thread images: 11
File: Capture.jpg (18 KB, 543x193) Image search: [Google]
Capture.jpg
18 KB, 543x193
There was a programming thread earlier, so I figured I'd make one to ask for some help.

I'm just starting to teach myself C++, and I'm using the book Programming Principles and Practices Using C++ by Bjarne Stroustrup. However, following the directions in the book doesn't work. Did I spend $50 on this thing that doesn't even work? Pic related is the code it told me to write.
>>
>>27964109
idk what that include is

try:

#include <iostream>
using namespace std;
>>
File: Capture.jpg (19 KB, 549x211) Image search: [Google]
Capture.jpg
19 KB, 549x211
>>27964143
That doesn't seem to be working either.
>>
>>27964143
This.

Anon I'm still here (though I should sleep). Can still email at [email protected]
>>
>>27964187
What is the error when you try to compile?
>>
File: 1451903451905.jpg (51 KB, 530x520) Image search: [Google]
1451903451905.jpg
51 KB, 530x520
>>27964143
>using namespace std;
>>
>>27964187
>doesn't seem to be working either
What's the problem here?
>>
>>27964188
Thanks anon, I will add your email to my contacts so I can email you if I need some help. I really appreciate it.

You get some sleep though, I am sure the other anons can help me out with this one, and I'll let you know if I need help on other things in the future.
>>
File: 1300044776986.jpg (17 KB, 250x250) Image search: [Google]
1300044776986.jpg
17 KB, 250x250
>>27964213
>worrying about namespace pollution for a beginner
>>
>>27964109
I didn't know we had Victoria's Secret models in /r9k/
>>
>>27964213
>naming any of your functions after Stdlib
>>27964237
That shit's hilarious. I encourage it wholeheartedly.
>>27964224
Yeah. Good night.
>>
File: Capture.jpg (25 KB, 547x238) Image search: [Google]
Capture.jpg
25 KB, 547x238
>>27964201
>>27964217
I just get this.
>>27964237
I don't know what you mean.
>>
>>27964264
Just try starting a new project with the same code and see what happens. It's hard to tell what you've done up until this point, so start fresh. Also make sure "debug" is selected at the top instead of "release". Attempt to run your program with CTRL + F5 (this will make it so the program stays on the screen rather than disappearing instantly soon as it hits the return 0)
>>
File: ddb.png (463 KB, 576x792) Image search: [Google]
ddb.png
463 KB, 576x792
>>27964264
I guess you didn't see the thread where the model was coding
>>
>>27964362
>that's because he IS the model
>>
File: Capture.jpg (52 KB, 927x591) Image search: [Google]
Capture.jpg
52 KB, 927x591
>>27964320
Now I'm getting this.

When I start off, there is a line that says #include "stdafx.h", should I try that one instead?
>>
>using what seems to be visual studio
>2016
>>
>>27964408
You can't even get hello world to run, you might as well give up.
>>
>>27964428
It's what the book recommended, I don't know what else to use.
>>
>>27964408
#include "stdafx.h is a visual studio thing. Pop it on top of the iostream include like this

#include "stdafx.h"
#include <iostream>
using namespace std;

Then tell me what happens.
>>
>>27964437
I've tried this numerous times in the past and given up because it seems I'm the most retarded person on Earth, since I can't even get the most simple program to run.
>>
>>27964446
honestly windows programming general is fucking shit

i have to install cygwin to make it tolerable
>>
Why is nobody pointing out he paid $50 for this book?

http://libgen.io/
>>
File: Capture.jpg (29 KB, 732x413) Image search: [Google]
Capture.jpg
29 KB, 732x413
>>27964458
Hey, that got it!
So does this just mean I should include

#include "stdafx.h"
#include <iostream>
using namespace std;

in all of my programs where the book says:
#include "std_lib_facilities.h"
?
>>
>>27964264
Really she's not "bad" she's learning. There's nothing wrong with that.. But people are making fun of it because she's a woman, she's a model and it's likely she's doing it for attention/validating herself/she's paid.
https://www.instagram.com/p/4Xp9sVkSjF/

Regardless. Research shows pretty girls doing geeky things discourages women going into tech.

Interesting how that works..
>>27964408
Do this.
Copy all your code.
Start a new project, make it a blank project.
Make your own sourcecode file (name doesn't matter).
Paste code.
Hit run.
I can help you over Skype >>27964188 later if you fail..

Good night.
>>
>>27964506
Because nobody cares and many people prefer physical textbooks
>>
>>27964506
i dont blame him

if im not reading a physical book i get distracted VERY easily
>>
>>27964532
This, it helps me stay focused.
>>27964523
Thank you for the suggestion, I will let you know if I run into any issues later on.
>>
>>27964519
No. It means you need to always include "stdafx.h"
>>
>>27964575
I see, thank you very much for the help. I'm going to keep going with my book now.

You guys are great.
>>
>>27964604
It might help if you look up what stdafx is
>>
>>27964506
I find physical text books x10 easier to learn from 2bh family.

>>27964519
>So does this just mean I should include etc.
If you're using visual studio and want to print things out to the screen like you just did, yeah pretty much. The <iostream> is the library that tells the computer how to put text on the screen and take input in from the keyboard (you will learn that later) and "stdafx.h" part is just a windows/visual studio thing (you wouldn't need to include it on Linux for example). Just some future tips for programming - google is your friend in 99% of circumstances. Google exactly what error you're getting and you will almost always find a solution. The programming community is one of the most elitist groups on the internet, so sometimes it's difficult. But stick with it and you'll be good in no time. Good luck, anon
>>
>>27964566
>>27964575
Shouldn't have to. I did >>27964523 works just fine.
But since it works now leave it be.
>>
>>27964575
more proof that IDEs like visual studio are shit and just get in your way
>>
>>27964623
>>27964523
Yeah, you can also do this to not have to include "stdafx.h". Just set up your project like that anon said and you probably won't even need it. You will still need <iostream> though.
>>
>>27964668
No they're extremely useful.
Especially if you give a shit about understanding your code.
>>
>>27964799
i think if you need an IDE to understand your code, you're doomed in the first place
>>
>>27964827
Yeah I'm sure all the professional software around right now was written in notepad++ and vim m8
>>
>>27964827
Depends on how complex things are. If you don't need one you haven't written big enough things.

Or you're not writing whatever you're writing nicely.
>>
>>27964646
You have to disable it within visual studio otherwise it gives the error
>>
>>27964863
the linux kernel was written by linus torvalds in a minimalist emacs clone

so whatever

same with openbsd, openssh and all that oher shit
>>
>>27964892
My point was for every autist who wants to feel like they're in the matrix, there are hundreds writing professional software using IDE's and other tools. It's a great learning experience to do "things from scratch" as it were, but it's not practical.
>>
>>27964519
Project -> (YourProjectName) Properties... -> C/C++ -> Precompiled Headers

Change "Precompiled Header" setting to "Not Using Precompiled Headers"
>>
>>27964143
IIRC, "std_lib_facilities.h" is something you create earlier in the text which is filled with stuff like "include <iostream>", "using namespace std;"

It is stuff you're supposed to just treat as boilerplate and wait until later where it is explained what all those things actually do. It is something that is supposed to get you running and seeing results more quickly.
>>
>>27964960
I would say it's actually the most practical. Like we saw with the OP, using an IDE can really gimp you up in ways you're not expecting. I have no idea what stdafx.h is and as a beginner I wouldn't want to see random libs being thrown into my source without understanding what they are. I know he could have just googled it but that's not always the first thing that comes to mind as a beginner. Writing in gedit is a great way to really get the zeitgeist of c/c++ without having to learn a complicated editor such as emacs or vim at the same time.

t. engineer and part-time hacker
>>
>>27965208
Yeah, and on top of that, if you do it manually, you get to learn how Makefiles work, what a linker is, etc.
>>
OP
I see you're using windows. Let me give you a piece of advice.
I won't tell you to install linux yet (you will do it on your own at some point).
But do install cygwin (I think that's the name).
The basics of moving around in the shell, along with the write-compile-execute workflow takes no time to learn and in the long run is way better than go around clicking buttons.
Shit, if you're feeling bold you can try and start using Vim. I know what I'm telling you, bunch of mediocre programmers tell you you don't actually need it and that you're good enough with atom or codeblocks or even eclipse (fuck them). But you'd have to learn touch typing first. So yeah, don't rush into that until you feel curious about it, just do consider using a not-underpowered editor at some point in your career.
And have fun.
>>
File: latest-1.jpg (41 KB, 660x320) Image search: [Google]
latest-1.jpg
41 KB, 660x320
>>27965208
You're right, but...

>part-time hacker
KEK
>>
>>27966017
he's probably using the term hacking in the correct way

he's not talking about "cracking"
>>
Another thing that might help is, Visual Studio provides command-line compilers. If you look in the start menu category for Visual Studio, it has an option for a developer command prompt. In there, go to where you have your source code and do "cl (your source file.cpp)", which should spit out an exe in the same location.
https://msdn.microsoft.com/en-us/library/ms235639.aspx
Visual Studio is a total piece of shit, so this approach might be dramatically less confusing.
>>
File: 1460637312000.png (433 KB, 1000x581) Image search: [Google]
1460637312000.png
433 KB, 1000x581
>>27964213
It's the best choice when working in the std namespace near exclusively eat a dick

Try something like this OP

#include <iostream>
using namespace std;

int main()
{
cout << "Hello World" << endl;
return 0;
}

EDIT: nevermind I see that you got it.

Something to keep in mind as you code and when you learn about them, never ever be afraid to split your code into functions. It's worth learning, because it's the difference between bracket after bracket after bracket vs just typing v = doThing(variable). It's something I didn't do when I first started (I started with MATLAB and just started learning C++ this year) Just finish projects, and maybe post asking how you can improve it. You'll get memed on for easy shit, but if it's for your own personal interest nobody should have any beef.

Just always keep this in the back of your mind: Always ask yourself if you wrote efficient code. That's what separates a good programmer from Pajeet. Consistency, efficiency, and elegance.

I have none of those fug :DDD
>>
>>27966045
This guy gets it

blix blox
>>
>>27966822
>You'll get memed on for easy shit
Yeah you seem to be quite new at this.
programming is not about how hardcore you can be and how obscure your code gets. I get a kick from those programmers who frown upon python for not having static typing. For some reason these guys think using a "hard" language makes them superior... sigh.
Anyway, about that thing you mentioned, you should separate your language in reusability. Of course the *look* of the code matters because high level languages are made for human readability. So having a huge function with a lot of statements is horrid to read but so is a function that pretty much calls a function just to run through a loop.
Unless that loop is something you'll use somewhere else or at least outlines a well defined behaviour separate from the overall goal of the caller, your code will end up much too granular and difficult to track when reading the source.
Just some friendly advice
>>
>>27964646
>Just a neat way to pause the program
use system("pause"); instead
>>
>>27967994
That's a very nice windowism.
>>
>>27967910
static typing actually makes programming easier because then you can use static analysis features in your editor to make sure you aren't memeing yourself and doing stupid shit by accident
>>
>>27966679
use this OP, VS is really only good if you're making a windows forms program, anything else and you're just adding more frustration
Thread replies: 57
Thread images: 11

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.