| View previous topic :: View next topic |
| Author |
Message |
vegito616 Expert Cheater
Reputation: 0
Joined: 08 Jan 2006 Posts: 109
|
Posted: Sat Aug 09, 2008 9:42 am Post subject: Reading from a Text File |
|
|
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 |
|
 |
jackyyll Expert Cheater
Reputation: 0
Joined: 28 Jan 2008 Posts: 143 Location: here
|
|
| Back to top |
|
 |
vegito616 Expert Cheater
Reputation: 0
Joined: 08 Jan 2006 Posts: 109
|
Posted: Sat Aug 09, 2008 8:29 pm Post subject: |
|
|
| Could someone provide me with an example of reading a line of text from a text file?
|
|
| Back to top |
|
 |
XxOsirisxX Grandmaster Cheater Supreme
Reputation: 0
Joined: 30 Oct 2006 Posts: 1597
|
Posted: Sun Aug 10, 2008 12:47 am Post subject: |
|
|
| 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 |
|
 |
Engineer Expert Cheater
Reputation: 1
Joined: 25 Nov 2007 Posts: 170
|
Posted: Sun Aug 10, 2008 5:25 am Post subject: |
|
|
| 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 |
|
 |
vegito616 Expert Cheater
Reputation: 0
Joined: 08 Jan 2006 Posts: 109
|
Posted: Sun Aug 10, 2008 11:39 am Post subject: |
|
|
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 |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sun Aug 10, 2008 3:16 pm Post subject: |
|
|
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 |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Sun Aug 10, 2008 3:46 pm Post subject: |
|
|
Use the fstream library.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
|