I have to write a program that will read from a file and store it in an array. whenever i run the program however, it doesn't output the numbers that are in the file. please tell me what i'm doing wrong. Here's my code:
#include %26lt;iostream%26gt;
#include %26lt;fstream%26gt;
using namespace std;
int main()
{
const int ARRAY_SIZE = 10;
int numbers[ARRAY_SIZE];
int count;
ifstream inputFile;
inputFile.open("numbers.txt");
for (count = 0; count %26lt; ARRAY_SIZE; count++)
inputFile %26gt;%26gt; numbers[count];
inputFile.close();
cout %26lt;%26lt; "The numbers are: ";
for (count = 0; count %26lt; ARRAY_SIZE; count++)
cout %26lt;%26lt; numbers[count] %26lt;%26lt; " ";
cout %26lt;%26lt; endl;
return 0;
}
C++ program?
Is "numbers.txt" in the same directory as your executable? For example in Visual Studio; projectfolder/DEBUG/ or /RELEASE/.
Reply:shouldn't it be numbers[count] %26gt;%26gt;inputfile;
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment