I have been able to solve the heap sort problem. The problem i have now is how to input from a file into a string. Its not as easy as it sound. it begins wiht a letter e.g. 'I' that means insert, 'S' for search, 'R' for remove or delete, 'C' for change and 'P' for print, all on multiple lines.
An example of an input will be:
I 2 34 56 78
P
S 2 30
R 56
P
I 45 67 43 23 45
C 45
2007-11-15
16:53:23
·
1 answers
·
asked by
FrederickVonHausen
1
in
Computers & Internet
➔ Programming & Design
i am not new to programming, but i am not too sure i know how to parse. I am a bit stuck, here is what i got so far there was more but i always get to blocked paths and i have start all over again.
if (myfile.is_open()){
fstream fileoperative("out2.txt",ios::out);
ifstream myfile("data.txt");
char buf[1024];
myfile.getline(&buf[0], 1024)
I tried using char and converting the first character into a char, but i am stuck with all the rest being chars. I am sure there is a way to do this. ANYONE OUT THERE!!!
2007-11-15
17:15:10 ·
update #1
the ifstream file is called myfile, and i am outputting to a file called out.txt.
okay i understand what you mean by i am using the getline wrong. But how on earth am i supposed to read in a letter first, then insert all the rest into an array. Here is an example of a previous solution
string line;
int charnum;
int i;
string d;
ifstream myfile ("data2.txt");
if (myfile.is_open()){
fstream fileoperative("out2.txt",ios::out);
while (! myfile.eof() ){
getline (myfile,line);
istringstream ss(line);
charnum=0;
bool flag=false;
int command=0;
int treeversion=0;
while( ss >> d ) {
if(charnum==0){
if(d[1]==49)
treeversion=1;
else if(d[1]==50)
treeversion=2;
else if(d[1]==68){
cout<<"Are theses damn Trees the same? ";
fileoperative<
cout <<"They are not identical" << endl;
cout<
fileoperative<
}
2007-11-15
17:37:05 ·
update #2