Hello ALl im new just wanted to ask a quick question thanks.
so im writing a program that reads in data from a ".txt" file and im supposed to use it to do computations
so I figured i should write the values into an array(or 2D array)
so i wrote the code below:
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 and executes it appears as
5.52.12.74.3
one big value
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 i should go about with this problem?
thanks.
Ive read a few issues similar to mine on forums and got helped up too this far just not as far as my problem
#include "stdafx.h"
#include<iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <conio.h>
#define newline '\n'
usingnamespace std;
float result = 0;
int main()
{
// Read Data File into a 2-D Array
ifstream inFile ("example.txt");
inFile.precision(2);
inFile.setf(ios::fixed, ios::showpoint);
// Declare Variables to Store Array Information
int parcel [3] [3];
float dis [3];
int id [3];
int A=0;
int B=0;
int c=0;
// Text File
ifstream inStream;
inStream.open("example.txt");
if (inStream.fail()) {
cout<< "Can't open file!\n";
system("pause");
}
else {
while (!inStream.eof()) {
// write into Array
for (int i = 0; i <2; i++) {
inStream >> dis[i];
result =dis[i];
cout << result;"\n";
}
}
// Close File
inStream.close();
system("pause");
}
}
well actually how am i too reference lets say "24.2" so i can work on it separately, Also I did the computations on my value and im ready to write them back too another text file so i did
from a text file,
-writing it into an array
-* by 2
-but when i write it back to my text file i only get the last line and its not letting me save the whole array to a variable