Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
C++
Message
From
14/11/2010 20:59:22
 
 
To
All
General information
Forum:
Visual C++
Category:
Coding, syntax & commands
Title:
C++
Miscellaneous
Thread ID:
01489083
Message ID:
01489083
Views:
79
I wanted to ask a Question concerning C++ but wasn't exactly sure where to post it so sorry if this is the wrong forum

so im writing a program that reads in data from a ".txt" file and im supposed to use it to do computations
so i wrote this
// Read Data File into a 2 Dimensional Array
ifstream inFile ("example.txt");
inFile.precision(2);
inFile.setf(ios::fixed, ios::showpoint);
  
 
  // Declare Variables to Store Array Information
  int scores [3] [3];
float labs [3];
  int id [3];
  int A=0;
  int B=0;
  int c=0;
  	// Declare Stream and Open Text File
  	ifstream inStream;
  	inStream.open("example.txt");
 
  	if (inStream.fail()) {
  	cout<< "Can't open file!\n";
  	system("pause");
  	}
   	else {
  		while (!inStream.eof()) {
 
 		// Nested For Loops to Read Info from Text File into Array
  		for (int i = 0; i <2; i++) {
  		inStream >> labs[i];
		result =labs[i];
	//cout<<labs[1]<<endl;}
		
	
		cout << result;"\n";
		
	}
	
  	}
  	// Close File

  	inStream.close();
	system("pause");
		}
  }
-------------------------------
So this works except that my file "example.txt." looks like this
5.5 2.1
2.7 4.3

but when i write it into my array it appears as
5.52.12.74.3

is there a better way to write it into my array so ill be able to reference one value at a time? or a different way
thanks.
again srry if this is posted in error of location and wouldnt mind redirected to the correct area
Reply
Map
View

Click here to load this message in the networking platform