Hi everyone
Im just a new student in c++ and im trying to read data from a file
this file looks like
36 69 115 226 278 343 345 358 368 370 401 450 489 494 573 577 581 583 610 682 692 705 722 832 862 886 908 923 932 960 977
8 51 55 73 78 117 140 175 187 229 266 295 304 366 381 413 424 429 501 512 523 529 538 572 575 576 593 675 676 688 735 758 785 797 812 823 826 843 854 868 871 888 893 956 982
53 55 98 159 192 322 332 402 412 413 424 430 450 480 526 538 569 571 572 598 666 672 694 701 797 809 820 826 897 904 928 943 952 956 992
i want to put the items in the first column of the array for example in [0][0], [0][1]...etc
than i want to put the number of the line for each item in the second column of the array
i tried milloin time to do it but still confused with
my code is
and its messy right now
does anyone can help me to solve this problem?
any suggestions will be appreciated
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include<iomanip>
using namespace std ;
const long items=1000;
const long lines=100000;
long item_lines[items][lines];// array to save the item with its line
long i=0; // varibles for items
long j=0; // varibale for lines
int main()
{
std::string buffer;
int m=1;
int num;
int nu_lines; // varible for number of lines
// variable for input value
ifstream file( "Ayman.dat") ;
string line ;
vector<string> lines ;
while( getline(file, line ))
lines.push_back( line ) ;
//cout << "#lines: " << lines.size() << '\n' ;
nu_lines = lines.size();
cout<< "#lines: "<<nu_lines<<endl;
file.close();
//////////////////////////////////////////////////////////////////////////////////////////////////////
ifstream indata; // indata is like cin
indata.open("Ayman.dat"); // opens the file
if(!indata) { // file couldn't be opened
cout << "Error: file could not be opened" << endl;
exit(1);
}
indata >> num;
while(!indata.eof() )
{ // keep reading until end-of-file
item_lines[i][j]=num;
j++;
item_lines[i][j]=m;
i++;
j--;
indata >> num; // sets EOF flag if no value found
}
indata.close();
cout<< "#lines: "<<m<<endl;
cout << "the number of items is " << i<<endl;
for(int k=0; k<i; k++)
cout<<item_lines[k][j]<<" in line "<<item_lines[k][j+1]<<endl;
return 0;
}