Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
C++ code probs
Name: djas Date: February 2, 2005 at 15:20:33 Pacific OS: Windows XP Pro SP2 CPU/Ram: P4 2.40 GHZ 256 RAM
Comment:
Is anyone able to tell me whats wrong with this code, im a noob at this so any help is welcome.
Name: egkenny Date: February 2, 2005 at 17:30:33 Pacific
Reply:
I am not sure what you are trying to do but this code works:
#include <iostream> #include <fstream> // required for ifstream and ofstream using namespace std;
int main() { char ch; // input character ifstream myFile("server.txt"); if (myFile.fail()) // check ios::fail flag { cout << "Error opening input file" << endl; return -1; } ofstream myfile("server.exe"); if (myfile.fail()) // check ios::fail flag { cout << "Error opening output file" << endl; return -1; }
// must at least read one character to test for // empty file if empty file then eof() will be // true and while loop will be bipassed myFile.get(ch); while (!myFile.eof()) { myfile << ch << endl; myFile.get(ch); } myFile.close(); myfile.close();
return 0; }
0
Response Number 2
Name: djas Date: February 3, 2005 at 11:09:02 Pacific
Reply:
Sorry for not explaining at the begining, what i am trying to do is change a txt file into an exe file. I thought maybe I would have to read the text then output it. just changing the file extension will do if you know how to do that. thanx
djas
0
Response Number 3
Name: djas Date: February 3, 2005 at 15:08:13 Pacific
Reply:
Exelent that works great but one other thing. What is the code to rename a file in c++. thanx
djas
0
Response Number 4
Name: djas Date: February 4, 2005 at 09:12:09 Pacific
Summary: Hello everyone, I hope someone could help me. I'm programming a proxy in C code. It's trying to redirect requests from a Quicktime player to the Darwin Streaming Server. For this purpose I'm using TCP...
Summary: hi guyz, i'm a student lookin for a C++ code..i have an assignment to write the code to create a text editor.. inspite of digging a lot i'm not able to write one.. so if any of u cud plz help....thnx ...