Hi Guys,
I'm really struggling getting to grips with C++ I need to read a .txt file which contains something similar to this:
Eng.Speed Torque
1000.0, 34.55
3800.0, 46.58
6600.0, 47.44
9400.0, 48.75
12200.0, 39.79
15000.0, 24.61
I'm trying to:
.Open a file named torque1.txt
.extract the data
.I want to do something with the data (integrate using the trapezium rule)
.open torque2.txt and do the same
.open torque3.txt ...
I'll be able to write the trapezium rule bit, I'm just struggling to find out how to read numbers with decimals from a text file (I only have limited experience in python).
Is it possible to extract each number individually and store them in two arrays, eng.speed and torque.
This is my code so far:
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
string getcontent;
string filename;
int main()
{
for(int i = 1; i < 10; i++) // Produces file name torque(number).txt
{ // allowing looping
stringstream ss;
ss<< i;
filename = "torque" + ss.str() + ".txt";
ifstream openfile (filename); // Opens file to read
if(openfile.is_open())
{
while(! openfile.eof())
{
****Not sure how to read the data in****
}
}
****Do Something With Arrays****
}
cin.get();
}
I know I haven't tried to read the data in here, but everything I'm doing is wrong and I'm just hitting my head against a wall searching the internet.
Hopefully someone can help!
Thanks Kitson