NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page C++ help needed

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 05-16-2008, 05:58 AM THREAD STARTER               #1 (permalink)
Senior Member
 
majinbuu1023's Avatar
Join Date: Jan 2005
Location: New Zealand
Posts: 3,746
majinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud of
 



C++ help needed


I'm trying to learn C++ and when I compile
PHP Code:
#include <stdio.h>

int main()
{
    
printf("Lol its line one!\n");
    
printf("Line 2\n");
    
printf("LINE THREE WTFHAX;\n");

in Dev-C++ it just flashes for a second, the book im reading says press alt f5, but this is for C and is pretty old and uses the DOS operating system, anyone know what to do? I made a better script before but closed it because it would work

EDIT: figured it out
add this to the header
HTML Code:
#include <stdlib.h>
then add this
????: NamePros.com http://www.namepros.com/programming/470017-c-help-needed.html
PHP Code:
    system("pause"); 
to the bottom just above the } tag
Last edited by majinbuu1023; 05-16-2008 at 09:56 PM.
majinbuu1023 is offline  
Old 05-16-2008, 07:03 AM   #2 (permalink)
NamePros Expert
Join Date: Oct 2004
Location: South Carolina
Posts: 5,043
CrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond reputeCrazyTech has a reputation beyond repute
 


Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
The same thing happened to me when I was trying to create something similar, so I'll be watching this topic. I couldn't figure out why.
CrazyTech is offline  
Old 05-16-2008, 07:12 AM THREAD STARTER               #3 (permalink)
Senior Member
 
majinbuu1023's Avatar
Join Date: Jan 2005
Location: New Zealand
Posts: 3,746
majinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud ofmajinbuu1023 has much to be proud of
 



Awesome , this is really annoying me, I keep googling it but it isn't showing any results
majinbuu1023 is offline  
Old 05-17-2008, 11:07 AM   #4 (permalink)
NamePros Regular
 
pixelhero's Avatar
Join Date: May 2008
Location: England
Posts: 771
pixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to allpixelhero is a name known to all
 


Help The Homeless - Holiday 2009
Its because the compiler will run the main() method, printing all those lines and then close itself. As a program which leads to the end of the main() method assumes its finished with.

You need to pause it as you did, or ask it to wait for input using the std::cin function.

Alernatively export an exe and run it in command prompt
pixelhero is offline  
Old 05-19-2008, 07:14 PM   #5 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
For the record, you're coding C. In C++, your program would resemble:

Code:
#include <iostream>
using namespace std;

int main()
{
    cout << "Lol its line one!" << endl;
    cout << "Line 2" << endl;
    cout << "LINE THREE WTFHAX" << endl;
    system("pause");
    return 0;
}
Last edited by mholt; 05-20-2008 at 06:43 PM.
mholt is offline  
Old 05-20-2008, 04:10 AM   #6 (permalink)
NamePros Regular
 
qbert220's Avatar
Join Date: Jul 2007
Location: UK
Posts: 394
qbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to beholdqbert220 is a splendid one to behold
 


Protect Our Planet
Originally Posted by mholt
For the record, you're coding C.
C++ is a superset of C, so the original code is perfectly valid as either C or C++.
qbert220 is offline  
Old 05-20-2008, 10:55 AM   #7 (permalink)
NamePros Regular
 
Palyriot's Avatar
Join Date: Jul 2004
Location: Seattle, Wa
Posts: 596
Palyriot is a jewel in the roughPalyriot is a jewel in the roughPalyriot is a jewel in the rough
 



Well, I know in VB and C# you need to have a readline at the end of the program to make it idle and wait for the user to close the window. Just throw a readline command at the end of the program. It should work.

This might not be necessary in C though...
Palyriot is offline  
Old 05-20-2008, 11:34 AM   #8 (permalink)
NamePros Member
Join Date: Apr 2008
Posts: 82
risoknop is on a distinguished road
 



Quote:
#include <stdio.h>

int main()
{
printf("Lol its line one!\n");
printf("Line 2\n");
printf("LINE THREE WTFHAX;\n");
}
The problem is that this algorhitm doesn't wait for any input, it just resolves and shuts down. You need to include getchar() and return 0... Here:

Quote:
#include <stdio.h>

int main()
{
printf("Lol its line one!\n");
printf("Line 2\n");
printf("LINE THREE WTFHAX;\n");
getchar();
getchar();
return 0;
}
What does getchar() do? It stops the program and waits until you press enter - then the program continues (it can also be used to recognize what key did user press...).

return 0 ends the program.

By the way, that is pure C code - you don't use any C++ functions or libraries there In C++ it would be like this:

Quote:
#include <iostream>
using namespace std;

int main()
{
cout >> "Lol its line one!\n";
cout >> "Line 2\n";
cout >> "LINE THREE WTFHAX;\n";
getchar();
getchar();
????: NamePros.com http://www.namepros.com/showthread.php?t=470017
return 0;
}
risoknop is offline  
Old 05-20-2008, 06:38 PM   #9 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Originally Posted by risoknop
The problem is that this algorhitm doesn't wait for any input, it just resolves and shuts down. You need to include getchar() and return 0... Here:


What does getchar() do? It stops the program and waits until you press enter - then the program continues (it can also be used to recognize what key did user press...).

return 0 ends the program.

By the way, that is pure C code - you don't use any C++ functions or libraries there In C++ it would be like this:


Did you even read the thread - no - just his original post even? You just made yourself look rather unintelligent...

Originally Posted by qbert220
C++ is a superset of C, so the original code is perfectly valid as either C or C++.
True, however while the code is valid, I don't think that you can say the above code is C++ just by looking at that. I think in order for it to be C++ you need to use at least one C++ concept/aspect/feature.
????: NamePros.com http://www.namepros.com/showthread.php?t=470017

Header files with .h extension generally are not in and of themselves C++, as they are plain ol' C libraries.

Oh well. Doesn't matter.
mholt is offline  
Old 05-20-2008, 07:45 PM   #10 (permalink)
Senior Member
Join Date: Apr 2005
Location: Joliet, Illinois
Posts: 1,177
RageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to beholdRageD is a splendid one to behold
 


Child Abuse
Are you trying to create a command prompt or WinAPI? I can help if you let me know. I wouldn't recommend using 'printf' for command prompt in C++ programming with 'cout >>' - a lot better for your purposes.

-RageD
RageD is offline  
Old 05-21-2008, 11:39 AM   #11 (permalink)
NamePros Member
Join Date: Apr 2008
Posts: 82
risoknop is on a distinguished road
 



Quote:
Did you even read the thread - no - just his original post even? You just made yourself look rather unintelligent...
Maybe I'm just too tired but I really don't see how I've made myself look dumb. Care to explain?

If I did then I apologize.
risoknop is offline  
Old 05-21-2008, 12:30 PM   #12 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Well, he stated his resolution at the bottom of his OP, then you just repeated what was already said in the thread. I've made similar mistakes too... we all do.
mholt is offline  
Old 05-21-2008, 03:27 PM   #13 (permalink)
NamePros Member
Join Date: Apr 2008
Posts: 82
risoknop is on a distinguished road
 



Yeah I messed up. Sorry, my bad.
risoknop is offline  
Old 05-21-2008, 10:03 PM   #14 (permalink)
DNOA Member
Join Date: May 2004
Posts: 5,040
mholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant futuremholt has a brilliant future
 


Autism Marrow Donor Program 9/11/01 :: Never Forget Multiple Sclerosis Adoption Alzheimer's Lou Gehrig's Disease (ALS)
Lol, it's fine... I see you're sorta new here, so I guess it's just a heads up to read the thread. Anyway, welcome to NamePros. It's great that you are contributing, and we all love to see it!
mholt is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:27 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger