![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on Game help within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; I have started learnign c++ and i know i do have a logn way to go. But i decided to ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() Join Date: Feb 2006
Location: www.ultimatetalkforums.com Games, RPG, quickchat and more!
Posts: 531
Trader Feedback: 0
|
I have started learnign c++ and i know i do have a logn way to go. But i decided to make lots of mini tools in the process just to help me learn. In the future i will make them all fun in some way. i have been trying to make a program that asks for your name and you input your name and it sais it back
#include <iostream> using namespace std; int main() { int name; cout<<"Hello! What is your name?: "; cin>> name; cin.ignore(); cout<<"Hello "<< name <<"\n"; cin.get(); } that is what i have so far but it doesnt work please tell me what i did wrong...
__________________
[CENTER][COLOR=black][COLOR=black][URL="http://forums.qj.net/f-psp-firmware-discussion-253/t-psp-firmware-30-get-it-58053.html"][COLOR=cyan]would you upgrade?[/COLOR][/URL] [/COLOR][FONT=Times New Roman][COLOR=navy][URL="http://www.mindistortion.net/iwantyoursoul/?i_am=altunozara"]OMG ITS REAL![/URL][/COLOR][/FONT][COLOR=black] [URL="http://forums.qj.net/showthread.php?t=61756&page=1&pp=10"][COLOR=lime]Sony vs Nintendo[/COLOR][/URL][/COLOR][/COLOR][/CENTER] [CENTER] [/CENTER] [CENTER][URL="http://www.ultimatetalkforums.com"][IMG]http://i94.photobucket.com/albums/l82/Altunozara/userbar2.jpg[/IMG][/URL][/CENTER] [CENTER][SIZE=3]i [/SIZE][URL="http://forums.qj.net/www.gamingwell.com"][SIZE=3]wonder what could be under this hyperlink..hmm[/SIZE][/URL][/CENTER] [CENTER][SIZE=3][COLOR=green][B][I]Maniakc is awsome!!![/I][/B][/COLOR][/SIZE][/CENTER] [CENTER][FONT=Arial Black][SIZE=3][COLOR=#660099][I][U][URL="http://forums.qj.net/member.php?u=58299"]The Brain Pwns!!![/URL][/U][/I][/COLOR][/SIZE][/FONT][/CENTER] [COLOR=sienna]Creator of:[/COLOR][URL="http://forums.qj.net/f-psp-development-forum-11/t-release-go-go-go-beta-66652.html"][COLOR=sienna]GO GO GO![/COLOR][/URL] |
|
|
|
|
|
#2 |
![]() |
'int' is short for 'integer' meaning number, name isnt a number, change:
Code:
int name; Code:
char name[20]; I just tested it, that was your only problem, it should work now.
__________________
...Just Returned To The Scene... |
|
|
|
|
|
#3 | |
![]() ![]() is not posting very often
|
what about setting name to be a string?
__________________
Quote:
|
|
|
|
|
|
|
#4 | |
![]() ![]() Developer
|
Quote:
Read: http://www.nicollet.net/meta/tut.cpp -= Double Post =- Do not follow Jaso_psp's advice, he is giving you C advice rather then C++. Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout <<"Hello! What is your name?: ";
cin >> name;
cout << "Hello "<< name << endl;
cin.get();
}
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] Last edited by yaustar; 07-11-2007 at 02:09 AM.. Reason: Automerged Doublepost |
|
|
|
|
|
|
#10 |
![]() ![]() Developer
|
It only links what is needed and quite frankly, who cares if there is another 2k on the ELF size? If you are going to use C++ then make full use of the C++ standard library. That includes type safety and self sufficient objects (i.e. strings, vectors, lists). With C++ strings, you don't have to worry about NULL terminated strings or accidentally overrunning the char array. It is all handled internally which leaves the programmer to concentrate on the functionality of the program instead.
Use char * is just asking for trouble.
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
#12 | |
![]() ![]() Developer
|
Quote:
The C++ version is: Code:
std::string name = "I really don't give a crap what size this string is"; name = "nor do I have to bother dealing resizing or having to use the dangerous C string library to do this";
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
|
#14 |
![]() ![]() It's good to be free...
|
yaustar: If you don't strip the executable properly (which the PSP toolchain does anyway, so it doesn't matter), iostream can add upwards of 230kB to a file, IIRC.
Wow, I'm wrong. I just tested it in Cygwin with a basically empty file (not using the PSP toolchain, but whatever), and the file is over 400kB before stripping. It's 230kB AFTER stripping. That's a big deal compared to what you can usually pack into an executable.
__________________
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
|
|
|
|
|
|
#15 |
![]() ![]() Developer
|
This code is quite easily done by a beginner following your advice:
Code:
char *name1 = (char*)malloc(sizeof(char )*20); // Put a string in name1 char *name2 = (char*)malloc(sizeof(char )*20); // Put a string in name2 // Programmer attempts to make name2 string equal to name1 name1 = name2; // Whoops, memory leak through pointer reassignment
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
#16 | |
![]() ![]() Developer
|
Quote:
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
|
#17 | ||
![]() |
Quote:
-= Double Post =- Quote:
Last edited by pspballer07; 07-11-2007 at 11:02 AM.. Reason: Automerged Doublepost |
||
|
|
|
|
|
#18 | |
![]() ![]() Developer
|
Quote:
Even strcpy is dangerous: Code:
char name1[10] = ""; char name2[30] = "12345678901234567890123465789"; strcpy( name1, name2 ); // Whoops CRASH!
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
|
#19 | |
![]() ![]() It's good to be free...
|
Quote:
E] Yes, strcpy is very dangerous. It can lead to buffer overflows so quickly if you don't properly null-terminate a string, it's ridiculous. Even strncpy is dangerous if you don't know what you're doing.
__________________
pəʇuɒɹɓ ɹoɟ ɓuɪɥʇou əʞɒʇ
|
|
|
|
|
|
|
#20 |
![]() |
This is my code.
Spoiler for my code:
__________________
[U][URL="http://www.speedtest.net"][/URL][URL="http://www.speedtest.net/"][IMG]http://img459.imageshack.us/img459/5021/darkhuntercopyrz9jx4.png[/IMG][/URL][/U] |
|
|
|
|
|
#22 | |
![]() |
Quote:
__________________
[U][URL="http://www.speedtest.net"][/URL][URL="http://www.speedtest.net/"][IMG]http://img459.imageshack.us/img459/5021/darkhuntercopyrz9jx4.png[/IMG][/URL][/U] |
|
|
|
|
|
|
#23 | |
![]() |
Quote:
|
|
|
|
|
|
|
#24 |
![]() ![]() Developer
|
Using MSVS 8 2005
Code:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World" << endl;
}
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
#25 |
![]() |
well, this is for altunozara if they want to use char* or char[]
http://www.cplusplus.com/reference/clibrary/cstring/ |
|
|
|
|
|
#26 | ||
![]() ![]() Developer
|
Quote:
-= Double Post =- Quote:
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] Last edited by yaustar; 07-11-2007 at 11:17 AM.. Reason: Automerged Doublepost |
||
|
|
|
|
|
#28 |
![]() ![]() Developer
|
No, everybody's right but you pspballer07.
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
|
|
#29 |
![]() |
all he wanted to do is use chars or strings instead of integers, we showed him many ways of making his program WORK. You guys just went off on one lol.
__________________
...Just Returned To The Scene... |
|
|
|
|
|
#30 |
![]() ![]() Developer
|
The way I see it is that using C strings in a C++ program where C++ strings can be used is like drinking soup with a fork when you can easily use a spoon.
__________________
[Blog] [Portfolio] [Homebrew Illuminati - Serious Homebrew Development Forums] [I want to make Homebrew FAQ] [How I broke into the Games Industry] [Programming Book List] [Programming Article List] |
|
|
|
![]() |
| Tags |
| game |
| Thread Tools | |
|
|