i want to read a file of txt, and allthings in txt file is number,
then i convert the string to int, and put it in array wanna to print the array......but don't know why it is not successful, anyone can help me?
Code:
//run in dev- C++
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
string getcontent;
int number;
int array[10000];
for(int i=0; i<10000; i++)//array intizial
{array[i]=0;}
int i=0;
ifstream openfile("data.txt");//read file
if (openfile.is_open())
{
while(!openfile.eof())
{
openfile >> getcontent;
number=atoi(getcontent.c_str());
array[i]=number;
i++;
}
}
for(int i=0; i<10000; i++)//for print result
{
cout<<array[i]<<" ";
}
system("PAUSE");
}