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 


[C++] output text file problem

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

Joined: 13 May 2007
Posts: 53

PostPosted: Sat Dec 01, 2007 2:13 am    Post subject: [C++] output text file problem Reply with quote

i have a problem of getting the file to output txt file, it doesn't change
just wanted to know what command should i use?
btw, i using vb6
i try different method uch as struct/void before but got error something like "old list statement?"

Code:


////this script is make by myself not copy and paste.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int nsize = 20, fsize = 20;

int main()
{
   fstream inoutf;
   char filename[fsize];
   char name[nsize], grade;
   double emark, pmark, cmark, average;

   cout<<"Please input the following file name (abc.txt)\n";
   cout<<"that are using for this assignment.\n";
   cout<<"\nEnter File Name : ";
   cin>>filename;

   inoutf.open(filename, ios::in | ios::out);
   if (!inoutf)
   {
  cout<<"File not found! Whether file not exist or corrupted.\n";
  cout<<"Program aborted.\n";
  return 0;
   } 
     cout<<"NAME\t\tGrade\t Mark\n";
     cout<<"======\t\t=====   ====="<<endl;
     while(inoutf>>name>>emark>>pmark>>cmark)
     {
    average=(emark*7/10)+(pmark*15/100)+(emark*15/100);
       if(average>=70)
      grade='A';
       else if(average>=59)
      grade='B';
       else if(average>=40)
      grade='C';
       else if(average>=35)
      grade='D';
       else
      grade='F';
       cout<<setprecision(3);
       cout<<name<<"\t "<<average<<setw(8)<<grade<<endl;

     }
   inoutf.close();

   return 0;
}



Quote:

input :abc.txt

AlexChong
80 65 72
EricLeong
51 61 50
TonyEdward
49 54 52

output:abc.txt

Name grade mark
==== ==== ====
AlexChong 77.8 A
EricLeong 52.5 C
TonyEdward 49.8 C


make a mistake while typing.....
i wan my output text file shown like this. try .write before but failed

_________________
Back to top
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Sat Dec 01, 2007 3:16 am    Post subject: Reply with quote

use tabs \t like you did
_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
SnowWolf
Advanced Cheater
Reputation: 0

Joined: 13 May 2007
Posts: 53

PostPosted: Sat Dec 01, 2007 4:00 am    Post subject: Reply with quote

no, what i mean the output text file should be shown as the same as the dos that i put white box.
but i only get the output text file that i get is same as previous1

Quote:

example:
input (abc.txt)
abc
12 23 24
bcc
12 23 45
ddd
56 67 78

but the
output test file i get still same(abc.txt)
abc
12 23 24
bcc
12 23 45
ddd
56 67 78

the output text file i expect is like this (abc.txt)
Name Grade Mark
==== ===== ====
abc 15.5 F
bcc 18.6 F
ddd 61.0 B

_________________
Back to top
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Sat Dec 01, 2007 4:23 am    Post subject: Reply with quote

Code:

////this script is make by myself not copy and paste.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int nsize = 20, fsize = 20;

     int main()
{
   fstream inoutf;
   char filename[fsize];
   char name[nsize], grade;
   double emark, pmark, cmark, average;

   cout<<"Please input the following file name (abc.txt)\n";
   cout<<"that are using for this assignment.\n";
   cout<<"\nEnter File Name : ";
   cin>>filename;

   inoutf.open(filename, ios::in | ios::out);
   if (!inoutf)
   {
  cout<<"File not found! Whether file not exist or corrupted.\n";
  cout<<"Program aborted.\n";
  return 0;
   }
     cout<<"NAME\t\tGrade\t Mark\n";
     cout<<"======\t\t=====   ====="<<endl;
     inoutf<<"NAME\t\tGrade\t Mark\n";
     inoutf<<"======\t\t=====   ====="<<endl;
     while(inoutf>>name>>emark>>pmark>>cmark)
     {
    average=(emark*7/10)+(pmark*15/100)+(emark*15/100);
       if(average>=70)
      grade='A';
       else if(average>=59)
      grade='B';
       else if(average>=40)
      grade='C';
       else if(average>=35)
      grade='D';
       else
      grade='F';
       cout<<setprecision(3);
       inoutf<<setprecision(3);
       cout<<name<<"\t "<<average<<setw(8)<<grade<<endl;
       inoutf<<name<<"\t "<<average<<setw(8)<<grade<<endl;
     }
   inoutf.close();

   return 0;
}

_________________

ASM/C++ Coder
Project Speranza lead developer
Back to top
View user's profile Send private message
SnowWolf
Advanced Cheater
Reputation: 0

Joined: 13 May 2007
Posts: 53

PostPosted: Sat Dec 01, 2007 4:43 am    Post subject: Reply with quote

ty Smile
although still got a bit problem, i will try to solve myself Smile

_________________
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