Hi guys, i'm new at C++ and i'm currently learning how to integrate functions to read consecutive integers off a .txt file.
This is the part I DON'T get. Basically I have a function to detect a palindrome number, but how do i get it to be used to read an external .txt file? I listed the function before the main() . But where do i put the file stream and how do i link it to read the .txt file on my desktop?
Reading the numbers and checking if they are palindromes are 2 totally different things.
I would declare the input stream in main, read the numbers in a loop and call the function for palindromes on each number.
Hint: You can edit your post, highlight your code and press the <> formatting button.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
Andy
Edit:
P.S. do not forget to show the input file you are using. This way everyone can use the same information. It also helps to know what the file looks like when it comes to reading the file.
Hi andy, I was more looking for a general understanding of the concept, but here is my code.
Basically I have a function to check if a number is a palindrome, and i am supposed to run a list of numbers from a .txt file through this function. in the end results its supposed to print out how many numbers are palindromes and how many are not. My code is still incomplete of course but any advice will be very helpful thanks!
___________________________
#include <iostream>
#include <fstream>
using namespace std;
bool numberPalindrome(int x)
{
int palinDrome = 0, notPalinDrome = 0;
int y, r = 0;