Hello I have created a sucsessful prime number finder however I wish to retrive the start number from a file the last line shows how I tried to do this however it failed any solutions ?

/* By Kelechi Nze 
	My first prime project*/
#include <windows.h>
#include <iostream>
#include <fstream>
#include <string>
#define NEWLINE "\n"
using namespace std;
struct primes //My Prime number structure
	{
		fstream startnumb; //The starting number file
		ofstream passnumb; //Passnumb: where primes are stored
		int number, factor, divider;	/*Number: The actulal prime number "finder" 
											factor: What's a factor
											Divider: What to divide the prime.number with to find if there is a prime there*/
	}prime;	//Only one member in the structure ? Yes !
	prime.passnumb.open("UserStorage.txt");
	prime.startnumb.open("startnumber.ini")
        prime.number = prime.startnumb;

It's maybe better when you change line 11 to: ifstream startnumb; You shouldn't forget to close the files when you don't need them anymore ...

BTW, on line 7 you're using #define to declare a constant, it's better to use const instead of #define ...

It's maybe better when you change line 11 to: ifstream startnumb; You shouldn't forget to close the files when you don't need them anymore ...

Thank You !
I'm going to change the number using fstream later and also thats not all of my code I closed the file later on. Someone close this thread.

It's maybe better when you change line 11 to: ifstream startnumb; You shouldn't forget to close the files when you don't need them anymore ...

BTW, on line 7 you're using #define to declare a constant, it's better to use const instead of #define ...

Why ?

Why ?

Consider the following program using #define :

#include <iostream>

using namespace std;

#define BEGIN 20
#define END 60
#define LENGTH END-BEGIN

int main()
{
	cout << "LENGTH = " << LENGTH << endl;
	cout << "2*LENGTH = " << 2*LENGTH << endl;
	return 0;
}

Well, it doesn't return the result you expected ...
You probably expected it would return 80 ...

You don't have this problem using const :

#include <iostream>

using namespace std;

int main()
{
	const int BEGIN = 20;
	const int END = 60;
	const int LENGTH = END-BEGIN;
	
	cout << "LENGTH = " << LENGTH << endl;
	cout << "2*LENGTH = " << 2*LENGTH << endl;
	return 0;
}

Hope this helps !

BTW, const is invented to avoid the use of #define , so why would you continue using #define if you can use a better (and more C++ like instruction) ??

This question has already been answered. Start a new discussion instead.