How I can read in those elements and store them into two different arrays., i.e. : the number in <?>
and the word in [?]
to be separately read in and stored.
<98>
Avs [adadada]
<45>
[adafaf] BBBHADA
asdadqd aada [Mammoth]
<-1> // ends the read
The rest of the info in the file is useless which do not require to be stored.
Edit:
Following the advice of one of the answers, here is my first attempt:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string.h>
using namespace std;
int main(int argc, char* argv[])
{
if(argc != 3)
cout<< "Error! Not enough file!"<<endl;
int** page = new int*[];
char** words = new char*[];
}
//---------------------------------------------------------
void readInput(int** page1, char** name1){
istream is;
char par1, par2;
int usefulVal;
is >> par1 >> usefulVal >> par2;
// check if any input
if(!is) return is;
// check for valid input format
if (par1 != '<' || par2 != '>'){
// set failbit to indicate invalid input format
is.clear(ios_base::failbit);
// assign input values to second argument
page1(usefulVal);
char par_1, par_2;
string string_value;
is >> par1 >> string_value >> par2;
if(!is) return is;
if (par_1 != '[' || par_2 != ']')
{
is.clear(ios_base::failbit);
return is;
}
name1(string_value);
return is;
}
Question:
1. Is there a way to read and store the above elements separately?
2. What am I doing wrong?
P.S.: I'm just trying out some C++. Hope someone can shed some light on it, thanks!