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 


Reading from a Text File

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
vegito616
Expert Cheater
Reputation: 0

Joined: 08 Jan 2006
Posts: 109

PostPosted: Sat Aug 09, 2008 9:42 am    Post subject: Reading from a Text File Reply with quote

I was wondering if someone could help me read a line of text from a text file.



And am I correct in reading a character of a string with this code

Code:

string Name = "Bob";
v = Name[0];
//Will 'v' now store the letter 'B'?
Back to top
View user's profile Send private message
jackyyll
Expert Cheater
Reputation: 0

Joined: 28 Jan 2008
Posts: 143
Location: here

PostPosted: Sat Aug 09, 2008 10:08 am    Post subject: Reply with quote

If the variable v was previously defined, it would hold the character 'B'.


Reading files:
http://www.cplusplus.com/doc/tutorial/files.html
Back to top
View user's profile Send private message AIM Address MSN Messenger
vegito616
Expert Cheater
Reputation: 0

Joined: 08 Jan 2006
Posts: 109

PostPosted: Sat Aug 09, 2008 8:29 pm    Post subject: Reply with quote

Could someone provide me with an example of reading a line of text from a text file?
Back to top
View user's profile Send private message
XxOsirisxX
Grandmaster Cheater Supreme
Reputation: 0

Joined: 30 Oct 2006
Posts: 1597

PostPosted: Sun Aug 10, 2008 12:47 am    Post subject: Reply with quote

vegito616 wrote:
Could someone provide me with an example of reading a line of text from a text file?


The own link example have your example answer.

Quote:
// reading a text file
#include <iostream> // I guess this needs no explain.
#include <fstream>
#include <string>
using namespace std;

int main () {
string line; // line become a string
ifstream myfile ("example.txt"); // input myfile = example.exe (which in the previous example of the link web site where writted
if (myfile.is_open()) // If the .txt is open then..
{
while (! myfile.eof() ) // While the .txt have'nt research the end then..
{
getline (myfile,line); // get the line as line which is the string
cout << line << endl; // print the line and makes a new line
}
myfile.close(); // close the .txt
}

else cout << "Unable to open file"; //if could not be open.. print that.

return 0;
}


=x

_________________

Back to top
View user's profile Send private message
Engineer
Expert Cheater
Reputation: 1

Joined: 25 Nov 2007
Posts: 170

PostPosted: Sun Aug 10, 2008 5:25 am    Post subject: Reply with quote

XxOsirisxX wrote:
vegito616 wrote:
Could someone provide me with an example of reading a line of text from a text file?


The own link example have your example answer.

Quote:
// reading a text file
#include <iostream> // I guess this needs no explain.
#include <fstream>
#include <string>
using namespace std;

int main () {
string line; // line become a string
ifstream myfile ("example.txt"); // input myfile = example.exe (which in the previous example of the link web site where writted
if (myfile.is_open()) // If the .txt is open then..
{
while (! myfile.eof() ) // While the .txt have'nt research the end then..
{
getline (myfile,line); // get the line as line which is the string
cout << line << endl; // print the line and makes a new line
}
myfile.close(); // close the .txt
}

else cout << "Unable to open file"; //if could not be open.. print that.

return 0;
}


=x



That one has errors (atleast for me)
Try:
Code:

/* Text file reader */
/* Includes */

#include <windows.h>
#include <fstream>
#include <string>
#include <iostream>
using namespace std;

/* Function */
int main( void ) {
string read;
ifstream reader ("input.txt");
    if (reader.is_open()) {
       while(! reader.eof()) {
               getline(reader,read);
               std::cout << read << endl;
               reader.close();
               }
               }
               else 
                   { std::cout << "Error: Could not read file." << endl;
                     
return 0;
}
}


(yes, I tested it)
Back to top
View user's profile Send private message
vegito616
Expert Cheater
Reputation: 0

Joined: 08 Jan 2006
Posts: 109

PostPosted: Sun Aug 10, 2008 11:39 am    Post subject: Reply with quote

Okay, thanks for the help, but now I have another problem.

How can I send a string with SendInput or Send/PostMessage that a user provides?
(P.S.: This is not for hacking purposes)
Back to top
View user's profile Send private message
kitterz
Grandmaster Cheater Supreme
Reputation: 0

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Sun Aug 10, 2008 3:03 pm    Post subject: Reply with quote

Next time use the search button.

PostMessage:

http://forum.cheatengine.org/viewtopic.php?p=2091924&sid=74e9bae180e6732a1e87ea314be48d34

SendInput:

Mouse:

Code:
         Input.type = INPUT_MOUSE;
         Input.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
         AltSendInput(1, &Input, sizeof(INPUT));

         Input.type = INPUT_MOUSE;
         Input.mi.dwFlags = MOUSEEVENTF_LEFTUP;
         AltSendInput(1, &Input, sizeof(INPUT));


Keys:

Code:
         Input.type = INPUT_KEYBOARD; // keybd_event
         Input.ki.wVk = vKey; // Virtual Key
         AltSendInput(1, &Input, sizeof(INPUT));


Postmessage parameters:
http://msdn.microsoft.com/en-us/library/ms644944(VS.85).aspx

SendInput parameters:
http://msdn.microsoft.com/en-us/library/ms646310.aspx
Back to top
View user's profile Send private message Send e-mail
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sun Aug 10, 2008 3:16 pm    Post subject: Reply with quote

To send a string, loop WM_CHAR messages (PostMessage)

Code:
for ( int i = 0; i <= (int)_tcslen(tszUserString)-1; i++ )
{
      PostMessage( hWnd, WM_CHAR, (WPARAM)tszUserString[i], 0 );
}

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

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Sun Aug 10, 2008 3:46 pm    Post subject: Reply with quote

Use the fstream library.
_________________
What dosen't kill you, usually does the second time.
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