1. Assume there was a valid file called cards.txt in the current directory containing 5 valid int values, each on its own line. It is needed to write the function that reads all values from file and then prints out: "lucky 7!" to the screen for every 7 it sees. Use the signature: void printSevens();
#include <iostream> #include <fstream> using namespace std; void printSevens(); int main() { printSevens(); return 0; } void printSevens() { ifstream inStream("cards.txt"); if (inStream.is_open()) { int number; while (inStream >> number) { if (number == 7) { cout << "Lucky 7!" << endl; } } inStream.close(); } else { cout << "can't find cards.txt!" << endl; } }
Get Answers For Free
Most questions answered within 1 hours.