Mar 3, 2015 at 6:10pm UTC
Can u see anything wrong with this code? Visual Studio does
//Give or take iostream.. No need to point that out.
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
#include <fstream>
using namespace std;
int main()
{ ifstream infile; ofstream outfile;
infile.open(“dataFile.dat”);
outfile.open(“out.dat”);
int number;
while (infile >> number)
{ if (number > 0)outfile << number << endl; }
infile.close();outfile.close(); return 0; }
Last edited on Mar 3, 2015 at 6:11pm UTC
Mar 3, 2015 at 6:11pm UTC
Can you tell us what errors you get? Would be helpful.
Last edited on Mar 3, 2015 at 6:11pm UTC
Mar 3, 2015 at 6:15pm UTC
Error 1 error C2065: '“dataFile' : undeclared identifier
Error 3 error C2065: '“out' : undeclared identifier
Error 2 error C2228: left of '.dat”' must have class/struct/union
Error 4 error C2228: left of '.dat”' must have class/struct/union
5 IntelliSense: identifier "“dataFile" is undefined
6 IntelliSense: identifier "“out" is undefined
Last edited on Mar 3, 2015 at 6:16pm UTC
Mar 3, 2015 at 6:17pm UTC
I dont see the "myFile" anywhere?
Mar 3, 2015 at 6:23pm UTC
Have you placed the "DataFile.dat" and "out.dat" inside your project?
Mar 3, 2015 at 6:30pm UTC
yes, I added it to the project and they are both in the same folder as the cpp file and they are spelt correctly
Mar 3, 2015 at 7:44pm UTC
I found the wrong finally, was very hard to spot. You arent using quotations for some reason.
infile.open(“dataFile.dat”);
The things around dataFile.dat is not what you want to use. You want to use these ones " "
Its the same with cout, strings etc, no idea how you messed that up
Mar 3, 2015 at 8:03pm UTC
I didn't see that coming. Thanks, I have no clue how that happened.....
Mar 3, 2015 at 8:16pm UTC
Haha! happens man :) Goodluck.
Mar 3, 2015 at 9:12pm UTC
Did you copy the code off of a website or from a Word document? Sometimes word processors will interject these types of quotation marks automatically.
Mar 4, 2015 at 6:05pm UTC
Type in word then copied/pasted to visual, so yea u are both right.