I\'m working on a program from class where we need to pull the numbers on the se
ID: 654197 • Letter: I
Question
I'm working on a program from class where we need to pull the numbers on the second line to average them out to put into an array code. We know how to do the array code, but I'm confused on what we'll use to do the find code. I'd assume we'd use "GetLine" function or data_text.find function but everytime I try and do it, nothing is being put into an output file.
That's an example of two of our chunks of code where we'll be pulling from. I need the numbers in bold to somehow be found by a program, and then found in a way so I can put it into an array code so it can be averaged out. Any thoughts on how I should approach this or do this?
Explanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream inFile;
ofstream outFile;
string data_text;
inFile.open ("input.txt");
outFile.open ("output.txt");
string indicator;
std::string s1("dataItemId");
std::string s2("timestamp");
std::string s3("name");
std::string s4("sequence");
if (!inFile)
{
cout<<"Failed to open file"<<endl;
}
while (inFile)
{
string s=data_text.substr(0,data_text.find('');
if((s1.compare(s)==0) || (s2.compare(s)==0) || (s3.compare(s)==0) || (s4.compare(s)==0))
{outFile<<data_text<<endl;}
else {outFile<<getline(inFile,data_text)<<endl;}
}
outFile.close();
inFile.close();
system("pause");
return 0;
}