My code is (using Atom):
Kindly note all the errors have been removed, but the output is wrong. At the end of the question, the output is listed.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char ch ;
int a, arr[2], i=0;
ifstream f(“num.txt”);
while(!f.eof())
{
f>>ch;
arr[i]=a;
}
f.close();
for(int i = 0 ; i<3 ; i++)
{
cout<<a[i]<<'\n';
}
return 0;
}
The data of 'num.txt' is '123'.
Error:
C:\Users\sy304\Documents\CPP\num_text.cpp:10:14: error: stray '\342' in program
ifstream f(“num.txt”);
^
C:\Users\sy304\Documents\CPP\num_text.cpp:10:15: error: stray '\200' in program
ifstream f(“num.txt”);
^
C:\Users\sy304\Documents\CPP\num_text.cpp:10:16: error: stray '\234' in program
ifstream f(“num.txt”);
^
C:\Users\sy304\Documents\CPP\num_text.cpp:10:24: error: stray '\342' in program
ifstream f(“num.txt”);
^
C:\Users\sy304\Documents\CPP\num_text.cpp:10:25: error: stray '\200' in program
ifstream f(“num.txt”);
^
C:\Users\sy304\Documents\CPP\num_text.cpp:10:26: error: stray '\235' in program
ifstream f(“num.txt”);
^
C:\Users\sy304\Documents\CPP\num_text.cpp: In function 'int main()':
C:\Users\sy304\Documents\CPP\num_text.cpp:10:17: error: 'num' was not declared in this scope
ifstream f(“num.txt”);
^~~
C:\Users\sy304\Documents\CPP\num_text.cpp:19:14: error: invalid types 'int[int]' for array subscript
cout<<a[i]<<'\n';
^
I am new to Atom. How can I get the solution for these errors?
Output:
51
1982955789
859839168