#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
ifstream myfile;
ofstream newfile;
string daFile;
myfile.open ("daFile.txt");
if (!myfile) //there was an error on open, file not found
{ cout << "Cannot open file, terminating program"<< endl;
system("pause") ;
exit (1);
}
newfile.open ("myfile");
myfile >> daFile; //this is called a priming read, only used once
while (!myfile.eof()) //or while (!infile.eof())
{
newfile <<daFile<< endl;
myfile>> daFile;
system("PAUSE");
};
myfile.close();
newfile.close ();
return 0; }
i jus put cout << name << endl; to try it out and i made it on notepad for both i tried changing "daFile.txt" to "c:\\temp\\daFile.text"; but still didnt function and i tried making for oth newfile and dafile
and now i changed it to myfile >> hello; and it doesnt function haha but it runs just does notin
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
usingnamespace std;
int main()
{
ofstream myfile("MyTrialFile.txt");
if (!myfile) //there was an error on open, file not found
{
cout << "Cannot open file, terminating program"<< endl;
system("pause") ;
return 1;
}
cout << "File opened. " << endl;
system("PAUSE");
return 0;
}
If the "File opened. " message appears use your operating systems search functionality to find the file with the correct name. Is your input file in this same directory?
What? You said your program was reporting that the file didn't open so, no it didn't open. In the program I supplied, if the "File opened." message appeared then yes the file opened.
You need to understand that when dealing with input streams and using the default open mode, the file must exist, it will not be created if it doesn't exist. With a output stream using the default open mode, if the file doesn't exist a empty file will be created. And also an output stream erases the contents of the file when you open it, when using the default open mode.
yea i made it work it transfers information from myfile to newfile
now im just trying to find a way to make a loop.
the problem was that for some reason my .txt files were saving inside of visual studios so i just moved them and copied their location
im glad i got it to run im behind 1 lab so i did this one because were working on it tomorrow and im behind on my other lab because it has to do with prime numbers and perfect, for some reason i cant get the formula to work lol
you helped alot haha cant believe the file was in the wrong spot lasted hours on this simple lab.