Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I read a sentence from a file?

Status
Not open for further replies.

jvff

Programmer
Apr 1, 2001
64
BR
Hello,
I got a class that is a translator, I need to get a sentence from a file to translate. How can I do that? Can somebody help me? Thank you,

JVFF
 
Can you give a short sample to understand better? John Fill
1c.bmp


ivfmd@mail.md
 
Hello,
Of course:

File1.eng:

Bye.


File2.por:

Tchau.


I got file1, need to read from file until the point, save to a char*, translate, delete from text the sentence discovered, and then repeat till EOF (end of file). Save to File2. Thank you,

JVFF
 
//there is a sample of parsing cpp
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
int main()
{
ifstream xx(&quot;xx.txt&quot;);
string dx;
while(!xx.eof())
{
xx>>dx;
cout<<dx<<endl;
if(dx==&quot;salut&quot;)cout<<&quot;pa&quot;<<endl;
else if(dx==&quot;hello&quot;)cout<<&quot;by&quot;<<endl;
}
return 0;
}
//below is what xx.txt contain
salut hello bonjour hello
--------------------------
if you want to output in a file
ofstream resultfile(&quot;result.txt&quot;);
resultfile<<&quot;pa&quot;<<endl;
..... John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top