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++]Strings and characters
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Tue Nov 24, 2009 6:00 pm    Post subject: Reply with quote

Fendaril wrote:
For a project such as this you REALLY do not need a class.




Do you make it a habit to continually challenge your intellectual superiors?

There is no reason to not use a class. The whole point of the project is to learn. He wouldn't learn anything if he treated C++ as a lenient version of C like the rest of this forum does.
Back to top
View user's profile Send private message
IMRobbie
Newbie cheater
Reputation: 0

Joined: 26 Sep 2009
Posts: 24

PostPosted: Tue Nov 24, 2009 6:03 pm    Post subject: Reply with quote

Flyte wrote:
This is what I mean by "thinking in classes".

Code:
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <functional>

using namespace std;

class MaskedString {
   const string m_string;
   set<char> m_letters;

   bool IsMasked(const char C) const {
      return (m_letters.find(C) == m_letters.end());
   }

public:

   MaskedString(const string & Target)
      : m_string(Target) {}

   string Masked() const {
      string ret(m_string);
      replace_if(ret.begin(), ret.end(), bind1st(mem_fun(&MaskedString::IsMasked), this), '-');
      return ret;
   }

   string Real() const {
      return m_string;
   }

   void Unmask(const char C) {
      m_letters.insert(C);
   }
};

int main()
{
   string random = "zorro";
   MaskedString zorro(random);

   zorro.Unmask('z');
   zorro.Unmask('r');

   cout << zorro.Masked() << endl;
   cout << zorro.Real() << endl;

   return 0;
}


I'm fairly new at the C++ language, I haven't really got into classes. =(

Fendaril wrote:

Loop through the string. If the inputted letter equals to a letter in the string display it. It is not hard.

Like I said you can index Strings like arrays.

Could something like this be used to find the occurrences?
Code:

#include <iostream>
#include <string>
using namespace std;

int main() {
   string guessWord = "Hello";
   string letter    = "";
   int letterPos    = 0;
   
   cout << "Enter a letter: ";
   cin >> letter;
   
   int numChars = guessWord.length();
   
   for(int x = 0; x < numChars; x++)
   {
      if(guessWord.find(letter, 0) != -1) {
         letterPos = guessWord.find(letter);
         cout << "Yes, letter " << letter << " was found!";
         cout << "\nThe letter you enter was found in the string at index position ";
         cout << letterPos << endl;
         
         x = numChars;
      } else {
         cout << "Nope\n";
         x = numChars;
      }
   }
   return 0;
}


Last edited by IMRobbie on Fri Jan 29, 2010 2:27 pm; edited 7 times in total
Back to top
View user's profile Send private message
Fendaril
Cheater
Reputation: 0

Joined: 08 Nov 2009
Posts: 27

PostPosted: Tue Nov 24, 2009 6:11 pm    Post subject: Reply with quote

yes.
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
Goto page Previous  1, 2
Page 2 of 2

 
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