Author Topic: File output  (Read 3179 times)

0 Members and 1 Guest are viewing this topic.

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
File output
« on: February 03, 2011, 01:49:51 am »
So I've been working on an app signer program for the Prizm when I came along a problem. What I'm trying to do is copy one file and output to another. I've already tried using the << operator, the put function, and the write function, but my compiler (Visual C++ 2010) does not support these.  :P  None of the shown examples work. Also VC++ 2010 does not support the seekp method. Any ideas.  ???
Code: [Select]
ifstream app(filename, ios::binary);
char Convbuf;                                        // buffer to hold one byte at a time from the Conversion app
for( int counter = 0  ; counter < 0x7000; counter++)
{
Conv.read(&Convbuf,1);
app << Convbuf;
}
Code: [Select]
ifstream app(filename, ios::binary);
char Convbuf;
Conv.seekg(0, ios::beg);
app.seekp(0, ios::beg);
Conv.read(&Convbuf,1);
for( int counter = 1  ; counter < 0x7000; counter++)
{
app.write(&Convbuf, 1);
Conv.seekg(counter);
app.seekp(counter);
}

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline TC01

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 344
  • Rating: +9/-0
    • View Profile
Re: File output
« Reply #1 on: February 03, 2011, 08:03:08 am »
I would use functions like "fwrite", "fread", "fopen", "fclose", etc: if VC++ 2010 doesn't support them, MSDN is a liar. :P

There's an example on the MSDN page for fread.



The userbars in my sig are links embedded links.

And in addition to calculator (and Python!) stuff, I mod Civilization 4 (frequently with Python).

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: File output
« Reply #2 on: February 03, 2011, 03:55:04 pm »
are you sure you are including the files them correctly?
Also, did you put: "using namespace std;" in the file, right after the includes?
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: File output
« Reply #3 on: February 03, 2011, 09:10:20 pm »
I would use functions like "fwrite", "fread", "fopen", "fclose", etc: if VC++ 2010 doesn't support them, MSDN is a liar. :P

There's an example on the MSDN page for fread.
It kinda bugs me that I have to use part of the C library in a C++ program, but oh well. I did try the fwrite, fopen, fread and the program did compile, but the program crashed after running it.
Code: [Select]
ifstream app(filename, ios::binary);
char Convbuf[0x7000];
char Convbuft;
FILE * appstream;
fopen_s(&appstream, filename, "w+t");
Conv.seekg(0, ios::beg);

for( int counter = 0  ; counter < 0x7001; counter++)
{
Conv.read(&Convbuft,1);
Convbuf[counter] = Convbuft;
}
fwrite(Convbuf, 0x7000, 0x7000, appstream);
cin.get();
return 0;
are you sure you are including the files them correctly?
Also, did you put: "using namespace std;" in the file, right after the includes?

Yes the fstream library is included along using namespace std. The problem is that fstream in VS will support some methods such as open, close, and read, but write is not included. This could be because I'm using the express version of the software and I don't want to pay $750 for the professional edition.
« Last Edit: February 03, 2011, 09:11:15 pm by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2898
  • Rating: +467/-17
    • View Profile
    • TI-Boy CE
Re: File output
« Reply #4 on: February 03, 2011, 09:19:51 pm »
Actually, I think it's because you defined the file object as ifstream, which only supports input operations. Try using ofstream for outputting.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: File output
« Reply #5 on: February 04, 2011, 12:07:37 am »
Actually, I think it's because you defined the file object as ifstream, which only supports input operations. Try using ofstream for outputting.
I've now tried both ofstream and fstream and neither support the write method. I've decided to post my full code and have commented the part that generated an error. It is near the end and is the only error in the code. The rest I have tested and works fine.
Code: [Select]
// app_signer.cpp : Defines the entry point for the console application.


#include "stdafx.h"
#include <fstream>
#include <iostream>
using namespace std;

int main(void)
{
ifstream codename("progname.txt", ios::in|ios::binary);
if(!codename.is_open())
{
cout << "cannot find progname.txt";
cin.get();
exit(1);
}
char hexfile[50];
while(!codename.eof())
{
codename.getline(hexfile, 49);
}
codename.close();
ifstream code(hexfile, ios::in|ios::binary);
if(!code.is_open())
{
cout << "cannot find " << hexfile;
cin.get();
exit(1);
}
int startcode;
int stopcode;
int sizecode;
startcode = code.tellg();
code.seekg (0, ios::end);
stopcode = code.tellg();
sizecode = stopcode - startcode;
code.seekg (0, ios::beg);
ifstream Conv("Conv.g3a", ios::in|ios::binary);
if(!Conv.is_open())
{
cout << "cannot find Conv.g3a";
cin.get();
exit(1);
}
char filename[50];
for(char counter = 0; counter < 50; counter++)
{
if(hexfile[counter] == '.')
{
for(char counter2 = 0; counter2 < counter; counter2++)
{
filename[counter2] = hexfile[counter2];
if(counter2 + 1 == counter)
{
filename[counter2 +1] = '.';
filename[counter2 +2] = 'g';
filename[counter2 +3] = '3';
filename[counter2 +4] = 'a';
for(char counter3 = counter2 +5; counter3 < counter; counter3++)
{
filename[counter3] = ' ';
}
break;
}

}
break;
}
}
ifstream app(filename, ios::binary);
char Convbuf;
ofstream app(filename, ios::out|ios::binary);
app.seekg(0, ios::beg);
Conv.seekg(0, ios::beg);
Conv.read(&Convbuf, 1);
for( int counter = 1  ; counter < 0x7001; counter++)
{
app.write(&Convbuf, 1);                          //ERROR: write method not recognized
Conv.seekg(counter);
app.seekg(counter);

}
cin.get();
return 0;
}
Edit: Okay I replaced the libraries with that of the Borland compiler which fixed the write issue, but now a new error pops up that says ifstream, fstream, ofstream is ambigious. ???
« Last Edit: February 04, 2011, 02:44:02 am by z80man »

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: File output
« Reply #6 on: February 06, 2011, 08:52:09 am »
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results: