Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::ifstream inFile;
- inFile.open(filename);
- std::string buffer = ""; // a full line of data
- std::string tokenA = ""; // first part of buffer
- std::string tokenB = ""; // second part of buffer
- int coeff, power;
- // Verify that the file is good
- while (inFile.good()) {
- std::getline(inFile, buffer, '\n');
- std::stringstream ss(buffer);
- if (buffer == "") { break; }
- std::getline(ss, tokenA, ' ');
- std::getline(ss, tokenB, ' ');
- try {
- coeff = std::stoi(tokenA);
- power = std::stoi(tokenB);
- } catch (...) {
- std::cout << "Only integers are allowed" << endl;
- return EXIT_FAILURE
- // Or maybe System.exit(1), my memory is fuzzy
- }
- // Insert the values into the linked list, possibly inside a wrapper
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement