Nov 28, 2016 at 3:40am UTC
Lets say my text file looks like this.
POS/DATE 1 2 3
A 40 11 16
B 30 12 17
C 20 13 18
D 10 14 19
E 90 15 20
There are 6 ROWS and 4 COLUMNS. Please note that "POS/DATE" is in the "0" index.
When i read the dates (1,2,3....) how do i NOT readin the "POS/DATE" on to the array.
Similarly, how do i not read in "POS/DATE" when i create an array for the pos. (A,B,C,D.....)??
Please help.
Here's my basic code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <array>
#include <sstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
const int datesSize = 30;
string datesArray[datesSize];
const int posSize = 13;
string posArray[posSize];
inFile.open("data.txt" );
if (!inFile)
cout << "Error Opening File\n" ;
else
{
for (int i = 0; i < datesSize; i++)
{
inFile >> datesArray[i];
cout << " " << datesArray[i];
}
for (int i = 0; i < posSize; i++)
{
inFile >> posArray[i];
cout << " " << posArray[i];
}
inFile.close();
}
cout << endl;
system("pause" );
return 0;
}
Last edited on Nov 28, 2016 at 3:41am UTC
Nov 28, 2016 at 8:48am UTC
Simply create a temporary variable and read it to this variable before you start feeding the array.
Nov 28, 2016 at 10:26am UTC
Your Program is working fine
Nov 28, 2016 at 4:16pm UTC
@coder777
How do i do that?
@bird1234
It works, but the array is reading, "POS/DATE".
I want to NOT read that.
Nov 28, 2016 at 4:26pm UTC
@EdwardMiller91
I'm new to coding, have no idea what he said. I tried coding and i'm stuck at above code. F$%^... :(
Nov 28, 2016 at 6:43pm UTC
Here is what i have so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
#include <array>
#include <sstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
const int datesSize = 50;
string datesArray[datesSize];
const int posSize = 13;
string posArray[posSize];
string dummy;
inFile.open("data.txt" );
if (!inFile)
cout << "Error Opening File\n" ;
else
{
for (int i = 0; i < datesSize; i++)
{
inFile >> datesArray[i];
cout << " " << datesArray[i];
}
for (int j = 0; j < posSize; j++)
{
inFile >> dummy;
inFile >> posArray[j];
cout << " " << posArray[j];
}
inFile.close();
}
cout << endl;
system("pause" );
return 0;
}
And still reading "POS/DATE"
Last edited on Nov 28, 2016 at 6:46pm UTC
Nov 29, 2016 at 7:05pm UTC
@Chervil, i finally got it. What @ coder777 and you told worked. Read it to a temporary string and ignore it.
Thank you.