I'm new to the getline function in C++.
I'm writing a simple program that creates a struct for a Fraction, which reads in a numerator and denominator. Then, I'm writing a void printFraction()
function which takes in the struct as a parameter and outputs the numerator divided by the denominator.
However, I'm getting an error that says that there is no matching function for getline
, and that it requires arguments but is only getting 2. How can I find what the problem is?
#include <iostream>
using namespace std;
struct Fraction {
int numerator;
int denominator;
};
void printFraction(Fraction f);
int main() {
Fraction f;
cout << "Please enter numerator";
getline(cin, f.numerator);
cout << "Please enter denominator";
getline(cin, f.denominator);
cin.ignore();
printFraction(f);
}
void printFraction(Fraction f) {
cout << f.numerator << "/" << f.denominator;
}