Hi i got an problem i need to read from an text file that i got from an excel file at start. so i want each block in the excel file to have one space at the array i saved it so it got seperated by ;
example:
4 ; 0,0
42 ; 0,0
15 ; 3,2
73 ; 5,4
61 ; 5,6
7 ; 4,6
so i've been trying to get some information in these threads and learned this
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string line;
string array[50];
int temp=0;
ifstream myfile ("example.txt");
if (myfile.is_open())
{
while (! myfile.eof())
{
getline (myfile,line, ';');
array[temp]=line;
temp++;
}
myfile.close();
}
else cout << "Unable to open file";
for (int a=0;a<=temp;a++)
{
cout<<array[a]<<endl;
}
return 0;
}
This one works fine because it seperates away the ; and writes it to my array bur since its an string i cant work on with it... i need it in int form so i can do my other calculations later on
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i = 0;
int array[20];
int max_read = 20;
int amountRead = 0;
std::ifstream in("example.txt",std::ios::in |std::ios::binary);
if(!in)
{
std::cout<<"Could not open file"<<std::endl;
return 1;
}
//this is where we are reading in the information into our array
while(in>>array[amountRead] && amountRead < max_read)
{
amountRead++;
}
for(i = 0; i < 20; i++)
{
cout<<array[i]<<endl;
}
return 0;
}
And this program are with int form but i cant get it to seperate and with this program i have to know how big the array is soposed to be. That wont work so well for me because this program is going to be used later on with some calculations and it can be different large everytime
thx for help :)