Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

C++ Console app, Hello World! Problem

Name: Anonymous 2006-07-05 19:44

Im just starting C++ but i have got stuck straight away!

I have:

#include <iostream>
using namespace std;

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


It works fine, but just as it appears, it closes..and in the tutorial it shows the console with: 'press any key to continue...' under 'Hello World!'. Please Help!

Name: Anonymous 2006-07-05 20:14 (sage)

either learn how to use windows or switch to a different operating system before you try to learn c++

Name: Anonymous 2006-07-05 20:24

Because that was a worthwhile statment

Name: Anonymous 2006-07-05 20:55

add system("pause");before the return

Name: Anonymous 2006-07-05 21:12

cin.get();

Name: Anonymous 2006-07-05 21:12 (sage)

You should run a command-line app from the CLI.

Name: Anonymous 2006-07-05 22:34

>>6 has the right idea

Name: Anonymous 2006-07-06 4:33

>>6
TO explain:
Just drag and drop your .exe file onto the black command.com window you have open...

it will run your program and return you to the command prompt.
Thats if you are running windows... if you are using mac/linux just use VI and compile and run from there

Name: Anonymous 2006-07-06 5:20 (sage)

>>8
command.com? Fuck that! cmd.exe ftw (unless your using win9x)

Anyway, I guess you can do it through command line, or you can do it the better way and double-click from explorer, given that you are using the system("pause") method or the dummy character acquisition presented by >>5

Name: lolz 2006-07-06 7:22 (sage)

If you have problems using commandshell programs, you possibly should stop learning a programming language and start learning to use your OS. >_>;;

Name: Anonymous 2006-07-06 9:03

>>1

 #include conio.h

then add something...i forgot what(lol), it will prompt you to hit any key to continue stuff

use da internet

Name: Anonymous 2006-07-06 11:49

conio.h is a nonstandard library which is pretty pointless for something like this. I would do what a couple people suggested already and run it in a shell...

>>10
Truth

Name: Anonymous 2006-07-06 15:13 (sage)

This whole discussion is retarded.

>>1
Fails for using \n and endl in the same line, lol

Name: Anonymous 2006-07-06 22:37

>>1
Oh please! Don't start with c++ as your first language! Start with c or something easier like python!

Ah well. At least it's good to see that you haven't started with the java faggotry.

Name: Anonymous 2006-07-07 1:01

>>14
THIS THREAD NEEDS MORE ENTERPRISE.

Name: Anonymous 2006-07-07 3:54

>>14
NO JAVA

Name: Anonymous 2006-07-07 18:14

I'm using MS Visual Studio.net 2005, so I shouldn't have to manually run the program from the console.

>>5
This works, but if I have already used cin, it will exit -due to it getting to that point before releasing the key from the first input. - I can just add a couple of cin's but that would be 'cheating' and generally very bad coding.

>>14
(I actually started with VB6 - which I have come to find inefficient for my needs) - All the C++ tutorials I’ve seen, have been very easy, I just find it annoying that the only way to see the output in the console is to run it in debug mode with a breakpoint at the end.

Name: Anonymous 2006-07-07 18:24

>>17
the problem stems from poor IDE design.  if you don't like the way MSVS.net handles console apps, i'd recommend getting a different compiler before i'd recommend screwing with the code itself to get around the issue.

me, i just use a MSYS/MinGW environment for console programs.  command line interface for both the compiler and testing the compiled program.  happy.

Name: Anonymous 2006-07-07 18:55

When I first got into C++ (shortly before getting right back out of it) I tried some version of Borland that happened to be on the university computers and it automagically inserted GUI code into my app so that my 'Hello, world!' printed into a textbox in a frame.

Name: Anonymous 2006-07-07 20:42

>>17
Hrm, at the end of your program, do something like:
cin.ignore(200, '\n');
cin.get()
which should work.

Anyway, in both MSVC6 and 2003 .NET, the 'Press any key to continue' comes up automatically.

Name: Anonymous 2006-07-07 20:59 (sage)

>>20
That is, if you use the execute option from the IDE.

Name: Anonymous 2006-07-08 0:27

Just curious though... why is code compiled with msvc2005 usually about 500KB smaller than code compiled under mingw?

Name: Anonymous 2006-07-08 0:28

YOU LOOK LIKE YOU NEED SOME PORN! HOT SHIT!

Name: Anonymous 2006-07-08 0:28

<PORN> DOWNLOAD THIS SHIT NOW YOU RETARDS! </PORN>

Name: Anonymous 2006-07-08 0:29

<PORN> THIRD MESSAGE IN A ROW IN CASE THE FIRST EIGHT DIDn"T GET THE MESAGE THROUGH!
DSAF ASDF ASDF sadf isajef 04w4pju8 8i FUCKING FIX THIS SHIT!

Name: Anonymous 2006-07-08 0:30

stop chimping, chimpy

Name: Anonymous 2006-07-08 0:37

Dear prog,
Related to this, I just figured out something weird.
#include <stdlib.h>
#include <stdio.h>

int main(void) {
    char text[BUFSIZ];
    int i;

    puts("enter a number");
    if (fgets(text, sizeof(text), stdin) != NULL) {
       i = atoi(text);
       printf("you entered %d\n", i);
    }
    return 0;
}
When I compile that with MingW, it skips the puts call entirely. I mean I could be doing anything but this happens all the time. Any idea? My code does work. It just comes out like:

$ ./junk
42
enter a number
you entered 42

Name: Anonymous 2006-07-08 1:35

>>27
It is outputting "enter a number" AFTER you enter the number?  Sounds like puts is only pushing the string to the buffer, but the buffer isn't getting flushed until printf is called.

Name: Anonymous 2006-07-08 2:32

Ah, of course, thanks 28.

Name: Anonymous 2006-07-08 10:06

Thanks 20, works fine.

Name: Anonymous 2006-11-07 12:20

>>1

Forget it, it's NP-complete.

Name: Anonymous 2006-11-10 14:32

>>27
sizeof(text) is not supposed to return BUFSIZ, it can give you anything instead (like the size of the pointer).

Name: Anonymous 2006-11-12 15:07

>>1
You fail for using C++ over C.

Name: Anonymous 2006-11-13 17:39

>>33
you fail for insulting yourself

Name: Anonymous 2006-11-14 6:39

>>34
He's actually right. C++ fails. Hard.

Name: Anonymous 2006-11-15 6:03

bump

Name: Anonymous 2006-11-15 8:23

>>35
Not really, no.

Name: Anonymous 2006-11-15 8:54

Two things, you don't need the /n cause the endl takes care of that for you. Add the line "system("pause");" right before the "return 0;" to make it pause.

Name: Anonymous 2006-11-15 9:40 (sage)

>>38
y/\//\\/

Name: Anonymous 2006-11-15 9:52 (sage)

>>39
sed: 1: "y/\//\\/": transform strings are not the same length
wtf?

Name: Anonymous 2006-11-18 14:15

>>14

hahahahahaha, you think c is an easy language!!

Name: Anonymous 2006-11-18 14:18

>>37

thank you

Name: Anonymous 2006-11-18 15:31

>>41
C is not the best for starters but it IS reasonably easy, or at least it doesn't suck. It's one thing to be easy and another thing to be easy to do things with. It's not easy to do string manipulation and higher level stuff in C. But the language itself is easy; I'd say far easier (and smaller) than Python, and it should be, being a low-level language. If C were actually harder than a high-level language supporting good OO, first-class functions, closures, etc., C would be a piece of shit. And it isn't. BTW, that's why C++ IS a piece of shit.

Name: Anonymous 2006-11-18 15:43

>>43
So you are saying C++ sucks just because it is a little more complicated than C because it has has good OO, first-class functions, closures, etc.?

Yes, those added features do make it a little harder, but in the end, they make things easier.  It is really not a good idea to evaluate languages on what learning them is like, although it's hard to evaluate them any other way.

Name: Anonymous 2006-11-18 16:28

C++ does not have 'good OO, first-class functions, closures, etc.' It has bad OO and none of the rest.

Way to fail hard.

Name: Anonymous 2006-11-18 17:13

>>45
used all around the scientific and financial world, way to fail hard? I'm rather proud of it

Name: Anonymous 2006-11-18 17:22

You should judge a language based on what can be done with it.

Name: Anonymous 2006-11-18 17:28

>>44
So you are saying C++ sucks just because it is a little more complicated than C because it has has good OO, first-class functions, closures, etc.?
You fail, C++ has none of those.

Name: Ok 2006-11-18 18:29

Here is the C++ code:
#include <iostream.h>
int main() {
cout << "Hello World!\n" << end;
getchar(); // wait for the user to press enter
return 0;
}
Here is the C code:
#include <stdio.h>
int main() {
printf("Hello World!\n");
getchar();
return 0;
}

Name: Whoops 2006-11-18 18:30

lolz in the C++ code i used \n and << endl; together.. >_>

Name: Anonymous 2006-11-18 21:06

Here's the Python code:
print 'Hello World!'
raw_input()º

Name: Anonymous 2006-11-18 21:07

>>51
WTF happened to my raw_input()

Name: Anonymous 2006-11-19 6:30

>>46
No I was saying that YOU fail hard for demonstrating you don't know what you're talking about. Assuming you're >>44. (which you are because Anonymous Anonymous is Anoooonymous)

Name: Anonymous 2006-11-19 6:52

>>53
I work in C++ with scientists, I don't need to prove anything to myself as I see it every day with my own eyes. All my friends have the same experience as I do and I just need to look at the "serious" job offers (not the J2EE crap) to have a proof of what I live. Now stfu and come back once you have some real life experience (being 15 years old does not count)

Name: Anonymous 2006-11-19 8:38

>>54
Massive ownage.

Name: Anonymous 2006-11-19 17:28

>>53
Being old doesn't make you right, grandpa!

Name: Anonymous 2006-11-19 18:54

>>54
If you see closures every day while working with C++ then you're obviously using a completely different language than the C++ everyone else uses. That, or you don't know what a closure is.

Name: Anonymous 2006-11-21 15:43

>>57
where did you saw "closures" in my message, dipshit!

Name: Anonymous 2006-11-22 11:15

>>58
So you are saying C++ sucks just because it is a little more complicated than C because it has has good OO, first-class functions, closures, etc.?

dipshit

Name: Anonymous 2006-11-22 12:36

>>59
C++? Closures? Are you high?

Name: Anonymous 2006-11-22 13:44

>>59
I didn't say that, dipshit. It's called "being anonymous."

Name: Anonymous 2006-11-22 14:47

Will you guys stop picking on C++ just because it has closures, functional programming is a good thing, you know.

Name: Anonymous 2006-11-23 4:54

Anonymous is talking to himself

Name: Anonymous 2006-11-23 6:19

404: Reading comprehension not found on this server.

Name: Anonymous 2006-11-23 10:58

>>62
Troll

Name: Anonymous 2006-11-26 12:29

#include <stdio.h>
char *msg = "Hello World\n";

void message(char *p) {
printf("%s", p);
}
main() {
message(msg);
return 0;
}

Name: Anonymous 2006-11-26 14:17

>>66

Wow, thats needlessly complicated.

Maybe next time you could use a structure of floats and do some casting. Whole of /prog/ would respect you, honest.

Name: Anonymous 2006-11-26 14:48

Great cuz i needed /prog/'s respect..
You fool it was complex on purpose.

Name: Anonymous 2006-11-26 15:01

#include <stdio.h>

void message(int msg,int a,int b,int c,int d,int e,int f,int g,int o,int l) {
printf("%c", (char)msg);
msg+=a;
printf("%c", (char)msg);
msg+=b;
printf("%c", (char)msg);
msg+=c;
printf("%c", (char)msg);
msg-=d;
printf("%c", (char)msg);
msg+=e;
printf("%c", (char)msg);
msg+=f;
printf("%c", (char)msg);
msg+=g;
printf("%c", (char)msg);
msg-=o;
printf("%c", (char)msg);
msg-=l;
printf("%c", (char)msg);
}
main() {
    message(72,29,7,3,79,55,24,3,6,8);
}

Name: Anonymous 2009-01-14 14:01

FIOC

Name: Anonymous 2010-06-07 6:53

Hi, I can spam /prog/ too, you faggot.

Also, smoke weed everyday.

Name: Anonymous 2010-06-26 9:59

ur gay

Name: Anonymous 2011-02-03 5:49

Name: Sgt.Kabu㗖kiman訹䰉 2012-05-28 19:22

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List