im so dumb! need help with hello world c++ project!

Started by
45 comments, last by wilhil 19 years, 12 months ago
#include <string>#include <iostream>int main(){    std::string str; // this is a string variable    std::cin >> str;    system(str.c_str()); // c_str() convert the string to const char *}


[edited by - Eriond on May 12, 2004 5:15:32 PM]
Advertisement
edit - previous post, thanks but i prefear the [256] thing for now! your way looks a bit more complicated!

Thanks, it worked great!

you have all helped loads!

I am expanding the program bit by bit, and it is getting good!

I want to learn hjow to do windows programming, but I think that will be some time.

I was wondering next if anyone can help me, how do i do switches, so that when someone from dos window can type blabla.exe /r e.t.c. it will do something?

also I was wondering how can I make a simple window pop up? I want to just make a very simple window with one line of text and a ok button that will quit, but I dont know the command to do this!

any help again is appreciated.

Thanks

[edited by - wilhil on May 12, 2004 5:19:27 PM]
>wilhil<
You could probably create a window using the Windows API or MFC. You should probably have a good understanding of C and C++ before trying Windows programming using the Windows API or MFC, however. Both APIs are rather hard to use for a beginner, so don't be upset if you don't understand something. You can find in depth information on the Windows API and MFC at http://msdn.microsoft.com and a decent tutorial for the Windows API at http://winprog.org/tutorial/, but it'll still be hard to use for a beginner. Good luck!

[edited by - andrewo on May 12, 2004 5:46:41 PM]
lol, isnt there anyway I can get it on screen and fiddle around with the stuff without any coding, all i want is one line of text and a exit button.

a little question, what is so visual about visual c++ So far I havent seen anything diffrent from the old c++ of just typing in files! the only good thing compared to that is the ide so it is neatly organised!
>wilhil<
Listen, not to be rude but you really need a good book on C/C++ to get to where you want to go. Asking little incremental questions on how to do things is fine if you don''t understand something you''re trying to learn, but try to work things through on your own first. That''s just my opinion, someone feel free to shout me down.

Anyway, for the "Visual" aspect of VC++ look at hte Resources tab. There you can define resources such as dialog boxes (forms), menus, icons and hook up code to certain controls.

Regards,
Jeff

[ CodeDread ]
That link is cool, it discusses everything from basics! (the second one, not the msdn one)

also, what does #include <tchar.h> do? I cancelled it out, as it was not in the tutorial i was following, but it comes as default on a vs 2003 console project

also, i simply hate books, I just cant conectrate on them (dyslexia)
>wilhil<
To pass in arguments to your program you use arc and argv which are the only parameters you are allowed to pass to the main() method.

Argc is the number of arguments passed to your program while argv is a pointer to an array of strings which contain the individual arguments. One point to note is the first argument is ALWAYS the name of the program so if you call your program like this:

myprog foo

then argv[0] will equal "myprog" and argv[1] will equal "foo".

Once you know the number of arguments it's dead easy to loop thorough and process each one.

I would also recommend that you get yourself a decent book if only for refernce if nothing else, there are plenty of free books/tutorials on the 'Net which you can use - this is a decent book which takes you through learning C++ and is divided up so it shouldn't be too hard to learn from.

EDIT: just to clarify, to pass arguments to your program declare your main method like this:

int main(int argc, char *argc[])

[edited by - Spudder on May 12, 2004 8:01:54 PM]

This topic is closed to new replies.

Advertisement