Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ Question.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Pseudo Xero
I post too much
Reputation: 0

Joined: 16 Feb 2007
Posts: 2607

PostPosted: Wed Aug 22, 2007 1:23 am    Post subject: C++ Question. Reply with quote

Blegh, started C++ not too long ago.
Only problem is I don't know how to use a if command to see if the user input == "somestring".
I already know how to use the if command in general, but I get compiling errors if I use if (inputvariable == "something") {.

It might be something simple... but i couldn't find anything about it on google. Neutral

Thanks...
By the way, I'm using Visual C++ 6.

_________________
haxory' wrote:
can't VB do anything??
windows is programmed using VB right? correct me if im wrong.

so all things in windows you have like the start menu is a windows form too.
Back to top
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Wed Aug 22, 2007 3:04 am    Post subject: Reply with quote

if(!strcmp(a1,a2))
_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
Pseudo Xero
I post too much
Reputation: 0

Joined: 16 Feb 2007
Posts: 2607

PostPosted: Wed Aug 22, 2007 3:50 am    Post subject: Reply with quote

Robotex wrote:
if(!strcmp(a1,a2))

Thanks.
eh, I don't really get strcmp...
I haven't noticed any bad habits, but might be because of a previous language I learned. Surprised

Here's the code I have, obviously there's compiling errors...
Code:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main ()
{
   char *a1 = Input
   char *a2 = "k\o!}RmR=944QuzpFd~@`{fDF7n3g{A-"
      int Input
  cout << "Password: ";
  cin >> Input;
  if (!strcmp(a1, a2)) {
     cout << "Correct password...\n";
  else
     cout << "Wrong password, try again...\n";
  }
  return 0;
}

Anyone mind putting me in the right direction? Razz

_________________
haxory' wrote:
can't VB do anything??
windows is programmed using VB right? correct me if im wrong.

so all things in windows you have like the start menu is a windows form too.
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Aug 22, 2007 4:07 am    Post subject: Reply with quote

Using std::string allows you to do "if" compares.

Code:
#include <iostream>
#include <string>

int main(int argc, char* argv[])
{
  std::string input;
  std::string compare("asdasd");

  std::getline(std::cin, input);

  if(input==compare)
    std::cout << "Hurray!" << std::endl;
  else
    std::cout << "Blah." << std::endl;

  return EXIT_SUCCESS;
}
Back to top
View user's profile Send private message
TheSorc3r3r
I post too much
Reputation: 0

Joined: 06 Sep 2006
Posts: 2404

PostPosted: Wed Aug 22, 2007 7:56 am    Post subject: Reply with quote

you don't need to use std::string to compare strings.

xenephobe, you're forgetting semicolons, you can't declare a string without "".

Code:
#include <stdlib.h>
#include <iostream>
using namespace std;

int main()
{
   char input[256];
   cout << "Password pl0x: ";
   cin >> input;
   if (!strcmp(input, "asdasd")) cout << "Good job!\n";
   else cout << "Faiil\n";
   cin.get();
   return 0;
}
something like that
_________________


Don't laugh, I'm still learning photoshop!
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Aug 22, 2007 8:19 am    Post subject: Reply with quote

TheSorc3r3r wrote:
you don't need to use std::string to compare strings.
Sigh. I wasn't saying that you need 'em, but you can use 'em.

IMO using char [] is old fashioned and that's why I prefer strings. Why to learn first the old way of doing stuff and then move to modern? There's no point.

char [] also is more like C syntax than C++ syntax, I think. strcmp is also a C command. It's from cstdlib, isn't it? And C stands for C :)

And btw.. You should be including cstdlib, not stdlib.h.

These are my thoughts, you don't have to agree them. There's no need to tell me, if you don't agree.
Back to top
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Wed Aug 22, 2007 8:22 am    Post subject: Reply with quote

Jani wrote:
Why to learn first the old way of doing stuff and then move to modern? There's no point.


Reinventing the wheel is fun Very Happy hahaha

Many ways to do it, I'd rather use strings like you did yourself... However if you where used to C style code - it could be faster to whip code using char[]


though that's ugly if your need to play nice with your memory allocations..

_________________
0x7A 0x61 0x72 0x74

TEAM RESURRECTiON
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Aug 22, 2007 8:49 am    Post subject: Reply with quote

isnt strcmp from the String library? ....
_________________
Back to top
View user's profile Send private message
TheSorc3r3r
I post too much
Reputation: 0

Joined: 06 Sep 2006
Posts: 2404

PostPosted: Wed Aug 22, 2007 3:28 pm    Post subject: Reply with quote

lurc, the string library is part of the C library.

idk, Jani, char arrays are the way I prefer; I never actually understood strings in memory until I used char arrays/pointers. Doesn't really matter though Razz

_________________


Don't laugh, I'm still learning photoshop!
Back to top
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Wed Aug 22, 2007 3:38 pm    Post subject: Reply with quote

TheSorc3r3r wrote:
lurc, the string library is part of the C library.

idk, Jani, char arrays are the way I prefer; I never actually understood strings in memory until I used char arrays/pointers. Doesn't really matter though Razz


the problem with using char arrays memory leaks/buffer overflows which you find when you start trying to secure code... it's "safer" to use strings

you only really notice the difference when initializing the two - the perform the same for the most part.

that being said - i often use char arrays for small applications because it's easy to manipulate (the way i was taught to program)

here is a nice thread that discusses the two;
http://www.thescripts.com/forum/thread432603.html


more specificly;
arrays are evil (good read)

_________________
0x7A 0x61 0x72 0x74

TEAM RESURRECTiON
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Aug 22, 2007 4:21 pm    Post subject: Reply with quote

TheSorc3r3r wrote:
lurc, the string library is part of the C library.


i know that.... the poster above said that it was part of the stdlib.h or cstdlib

THERE THE SAME THING

_________________
Back to top
View user's profile Send private message
Pseudo Xero
I post too much
Reputation: 0

Joined: 16 Feb 2007
Posts: 2607

PostPosted: Wed Aug 22, 2007 4:55 pm    Post subject: Reply with quote

Thanks for the help, everyone.
I didn't even understand the basic form of a C++ app. Shocked
I got it to compile with no trouble, hopefully I'll be able to find what I need through google now.

_________________
haxory' wrote:
can't VB do anything??
windows is programmed using VB right? correct me if im wrong.

so all things in windows you have like the start menu is a windows form too.
Back to top
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Wed Aug 22, 2007 11:50 pm    Post subject: Reply with quote

use arrays when you are sure the code won't exceed the limit or you need high speed performance (in this case you would "reinvent the wheel" yourself, adapting it to your needs)
it's all a matter of programming needs

_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Aug 23, 2007 3:22 am    Post subject: Reply with quote

@TheSorc3r3r: C++ is an object oriented programming languange. "char" strings aren't objects unlike std::string's.. Try:
Code:
char test[] = "test";
std::cout << test.length();
and
Code:
std::string test("test");
std::cout << test.length();
:P

lurc wrote:
i know that.... the poster above said that it was part of the stdlib.h or cstdlib

THERE THE SAME THING
I do know that. I just told TheSorc3r3r to include cstdlib instead of stdlib.h, because cstdlib is the "c++ version" of it.

Robotex got the point anyway. It depends on the needs. I guess that the thread starter isn't in a competition where speed matters :P
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites