I just start learning c++ programming and I am using xcode on my mac.
I have a question about file I/O(maybe a very silly one)
I tried to open Scopy.cpp and copy the content to another file Scopy2.cpp.
I put both of the file in the directory same as the project.
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in("Scopy.cpp"); // Open for reading
ofstream out("Scopy2.cpp"); // Open for writing
string s;
while(getline(in, s)) // Discards newline char
out << s << "\n"; // ... must add it back
}
but nothing happened after I run the code.
Please tell me how to do it in the right way?
I have a question about file I/O(maybe a very silly one)
I tried to open Scopy.cpp and copy the content to another file Scopy2.cpp.
I put both of the file in the directory same as the project.
#include <string>
#include <fstream>
using namespace std;
int main() {
ifstream in("Scopy.cpp"); // Open for reading
ofstream out("Scopy2.cpp"); // Open for writing
string s;
while(getline(in, s)) // Discards newline char
out << s << "\n"; // ... must add it back
}
but nothing happened after I run the code.
Please tell me how to do it in the right way?