Convert iostream to stdio

Hi everyone, I am new here and also new to programming.

I am given a list of codes in the type of <iostream>,
but the codes that I've learnt is in the type of <stdio.h>,
is there any reference of comparism between these two types so that I can convert it to the one I want?


Below is the code,

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

int main ()
{
// Declare Variable

ifstream readID,readMatch,readDef;
string x;
string Input;
string edit ("?");
string ID, WORD;
int notAvailable, SizeStr, counts;
string defString, idDef, DispString;


//////////////////////////////////////////////

readID.open("ID.txt");
if (!readID)
{
cerr << "Unable to open file datafile.txt";
return 0; // call system to stop
}

readID >> x;
readID.close();
cout<<"My dictionary. # of entries: "<<x<<". (enter '?' to enter edit mode.) "<<endl;
cout<<"Search: ";
cin >> Input;

if (Input.compare(edit) != 1)
{
//edit part
cout<<"Edit mode"<<endl;
cout<<"1. Add word"<<endl;
cout<<"2. Delete word"<<endl;
cout<<"3. Set display option"<<endl;
cout<<"4. Exit display mode"<<endl;
///////////////////////////////
}
else
{
//Matching part
notAvailable = 1;

readMatch.open("dict.txt");

if (!readMatch)
{
cerr << "Unable to open file datafile.txt";
return 0; // call system to stop
}

while(readMatch>>ID>>WORD)
{
if (Input.compare(WORD) == 0)
{
readDef.open("defination.txt");

counts = 1;
while (getline(readDef,defString))
{
idDef.assign(defString,0,3);

if(idDef.compare(ID)==0)
{
SizeStr=defString.size() - 6;

DispString.assign(defString,6,SizeStr);

cout<<counts<<". "<<DispString<<endl;
counts++;

}


}





//cout<<"Match "<<WORD<<endl;

notAvailable = 0;
}

}

if (notAvailable == 1)
cout<<"This word is no available in our Dictionary"<<endl;
readMatch.close();
}



// Checking the Input




///////////////////////////////////////////////////////////


//ofstream myfile;
//myfile.open ("example.txt");
//myfile << "Writing this to a file.\n";
//myfile.close();
return 0;
}



Hope there is someone who can help me,


P/S: My programming knowledge is VERY limited, I apologize for the dummy question
Thanks!
Try looking the the tutorial on file streams, http://www.cplusplus.com/doc/tutorial/files.html this shoudl have the info you need.
That's weird... I thought I had made a comment...

When you say "convert" do you mean "translate" (e.g. printf("Hello, World!\n") -> std::cout <<"Hello, World!"<<std::endl) or convert objects (e.g. FILE -> std::fstream)?
Erm, basically I wanna get the code to be able to use in C.

By [convert], I am trying to get the code above change to the one I am learning, e.g. <iostream> header should be <stdio.h> in what I learn,
how bout the other <fstream> header, ifstream variable type, I have got no idea at all.

Perhaps I should name my title in other way.
With the help from the tutorial, so far I am able to "convert" part of the code to the one I want, but now I am stuck at the while loop:

while(readMatch<<ID<<WORD);

Can anyone tell me what does this do?
readMatch is declared as an ifstream instance, so
readMatch>>ID>>WORD //Important: >> not <<
will read ID and WORD from the the associated file.
If this occurs without problem the expression will evalueate to TRUE, and the while will cause it to read the nect pair.
If there is a problem reading (including reaching end of file) this will set the error flags of readmatch, it will evaluate to false and exit the while loop.


Topic archived. No new replies allowed.