|
-
Nov 12th, 2000, 09:00 PM
#1
Thread Starter
Registered User
Hello i'm pratically a newbie to C++ i have only been programming in VB, but my problem is this: i am reading a book called "Thinking in C++" and they tell me this:
Code:
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main() {
ifstream in("CoryS.cpp"); //opening file for reading
ofstream out("CoryS2.cpp"); //opening file for writing
string s;
while(getline(in, s)) //discards newline char
out << s << "/n"; // ... must add it back
}
And it is suppose to copy the contents of one file into the other, and it does nothing i made the first file CoryS.cpp say "hello this is just a test" and the CoryS2.cpp a blank file with nothing in it....and it didn't work, anyoen know why/>
if so please post! 
Thanks for listening!
-
Nov 13th, 2000, 08:27 AM
#2
Frenzied Member
It works fine for me. Check if the files are in the same directory as the exe or else include the full path name.
Also change /n with \n
[code]
//this works
#include <string>
#include <fstream>
#include <iostream>
using namespace std;
int main() {
ifstream in("CoryS.cpp"); //opening file for reading
ofstream out("CoryS2.cpp"); //opening file for writing
string s;
while(getline(in, s)) //discards newline char
out << s << "\n"; // ... must add it back
return 1;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|