when you run an ifstream in c++ and go into a textfile what is the data in the file converted to? this is my code

#include <iostream.h>
#include <fstream.h>
#include "TGraph.h" 
#include <time.h>
#include "TDatime.h"





void deeznutz()

  {
 char inputFilename[] = "data.txt";
 
   ifstream inFile;
   
  int x;
  
  inFile.open("data.txt", ios::in);
  
   if (!inFile) {
     cerr << "Can't open input file " << "data.txt" << endl;
     exit(1);
   }

 const int MAX_SIZE = 20; 
int day[MAX_SIZE];
int score[MAX_SIZE];
int numRecords = 0;

int iTemp = 1;
int iNew = 1;

while (iTemp)
{
     iTemp = inFile >> day[numRecords];
     iNew  = inFile >> score[numRecords];
     
     std::cout << "iTemp  " << iTemp << std::endl;
     std::cout << "iNew   " << iNew  << std::endl;
     std::cout << "day:   " << day[numRecords] << std::endl;
     std::cout << "score: " << score[numRecords] << std::endl;
     std::cout << std::endl;
     
     iTemp = iTemp * iNew;
     numRecords++;
}

in the code the integers are paired up, so 1 with 2, 3 with 4 and so on. with the odd ordered one being day and even being order it also displays information for iTemp and iNew. when i run it i get this kind of error:
*** Interpreter error recovered ***
root [1] .x deeznutz.C
iTemp 137142600
iNew 137142600
day: 1
score: 2

iTemp 137142600
iNew 137142600
day: 3
score: 4

iTemp 137142600
iNew 137142600
day: 5
score: 6

iTemp 137142600
iNew 137142600
day: 7
score: 8

iTemp 137142600
iNew 137142600
day: 9
score: 10

iTemp 137142600
iNew 137142600
day: 0
score: 4631464

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

iTemp 137142600
iNew 137142600
day: 0
score: 0

Error: Array index out of range day -> [21] valid upto day[19] deeznutz.C:37:
*** Interpreter error recovered ***
i don't undertand, why is it out of range and why for iTemp and iNew i get these weird files? the text flile looks like this:
1 2 3 4 5 6 7 8 9 10

WTF?
Seems like you're even not using a compiler, but an interpreter...

iTemp = inFile >> day[numRecords];
iNew  = inFile >> score[numRecords];

iTemp and iNew are being assigned references to inFile, those values are not meaningful to you. I guess you wanted iTemp to match day[numRecords] and iNew to match score[numRecords]:

inFile >> day[numRecords];
inFile >> score[numRecords];

iTemp = day[numRecords];
iNew = score[numRecords];

But even with that, your loop condition isn't going to stop at the right place and the program will keep trying to go past the 19th index of day and score. What is this code supposed to do?

for your loop you should be using while(numRecords < 20) that will fix running the array out of bounds. as Tom Gunn stated about iTemp and iNew they are being assigned a number to the fstream object on the value you got from the file.

the main purpose of this program was to put the odd ordered integers in an array and the even ordered integers into another array. my main problem though is can i expand this concept to decimal numbers? does the "infile" functions allow me to retrieve non integer values?

operator>> is overloaded and will pick the right function for the type you want if there is an overload of that type. You can change int to float or double and the code will still work.

ok i think i understand what you mean.
my program is meant to read files that look like this

0.0196528006345034 2008 10 13 18 28 10        
0.0184036009013653 2008 10 13 18 28 24        
0.0188200008124113 2008 10 14 10 40 52        
0.0188200008124113 2008 10 14 10 41 10        
0.0192364007234573 2008 10 14 10 41 17        
0.0221512001007795 2008 10 16 07 35 20        
0.0246495995670557 2008 10 16 07 35 30

and what i'd like my program to do is to insert each value into one of 7 arrays, first being "tesla" array, second being the "year", third being the "month", and so on and so forth. this is what i have so far

#include <iostream.h>
#include <fstream.h>
"

void free()

  {
 char inputFilename[] = "Bdata.txt";
 
   ifstream inFile;
   
  int x;
  
  inFile.open("Bdata.txt", ios::in);
  
   if (!inFile) {
     cerr << "Can't open input file " << "Bdata.txt" << endl;
     exit(1);
   }
   
 const int MAX_SIZE = 10000; 
float BField[MAX_SIZE];
int year1[MAX_SIZE];
int month1[MAX_SIZE];
int day1[MAX_SIZE];
int hour1[MAX_SIZE;
int min1[MAX_SIZE];
int sec1[MAX_SIZE];
int numRecords = 0;

bool iTemp = true;
bool iNew = true;
bool iTool = true; 
bool iRate = true; 
bool iNew = true; 
bool iCool = true; 
bool iFool = true ; 

while (iFool && iTemp && iNew && iTool && iRate && iNew && iCool)

{	

	if (inFile >> BField[numRecords])
	iFool = true; 
	else 
	iFool = false; 

	if (inFile >> year1[numRecords])
	iTemp = true;
	else
	iTemp = false;
	
	if (inFile >> month1[numRecords])
	iNew = true;
	else
	iNew = false;
     
	if (inFile >> day1[numRecords])
	iTool = true; 
	else
	iTool = false; 
	
	if (infile >> hour1[numRecords])
	iRate = true;
	else 
	iRate = false; 
	
	if (infile >> min1[numRecords]) 
	iNew = true; 
	else 
	iNew = false; 
	
	if (infile >> sec1[numRecords])
	iCool = true; 
	else
	iNew = false; 
	
	
     std::cout << "iFool  " << iFool << std::endl;
     std::cout << "iTemp   " << iTemp  << std::endl;
     std::cout << "iNew   " << iNew  << std::endl;
     std::cout << "iTool   " << iTool  << std::endl;
     std::cout << "iRate   " << iRate  << std::endl;
     std::cout << "iNew" << iNew  << std::endl;
     std::cout << "iCool   " << iCool  << std::endl;
     
     
     std::cout << "BField:   " << BField[numRecords] << std::endl;
     std::cout << "year: " << year1[numRecords] << std::endl;
     std::cout << "month:   " << month1[numRecords] << std::endl;
     std::cout << "day:   " << day1[numRecords] << std::endl;
     std::cout << "hour:   " << hour1[numRecords] << std::endl;
     std::cout << "min:   " << min1[numRecords] << std::endl;
     std::cout << "sec:   " << sec1[numRecords] << std::endl;
     
     
     std::cout << std::endl;
     
     numRecords++;
}
for (int i = 0; i < numRecords; i++)

cout << i << "   " << BField[i] << "   " << year[i] << "   " << month[i] << "   " << day[i] << "   " << hour[i] << "   " << min[i] << "   " << sec[i] << endl;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.