0
string resistance;
ifstream in;
in.open(filename);
while (!in.eof())
{
    getline(in, resistance);
    cout << resistance <<endl;
}
in.close();

That is the code im using to read from the file. The output from the file is: for example:

10 25 10 60 45 35

10 45 23 45 65 88

I want to take each line and perform a mathematical operation by each each value of the line to a variable

user3011154
  • 11
  • 1
  • 2

2 Answers2

0

First, split the string, then convert those to numbers using atoi, then loop through those values are performing the operations.

Community
  • 1
  • 1
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
0

in C++11 you can use std::stoi function:

istringstream iss( resistance);
istream_iterator<string> it = iss.begin();
while( it != iss.end()) {
    int value = stoi( *it++);
    //... do something
}
4pie0
  • 29,204
  • 9
  • 82
  • 118