hi im trying to make a "settings" that they are on c++
and saving on text documents
here is the code

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main(){
	fstream first("firstt.txt");;
	fstream File("file.txt");
	string firsttime;
	string blah1 = "enable";
	string blah2 = "disable";
	getline(first, firsttime);
	if(firsttime=="not"){

	} else{
		cout << "first time settings (to be changed at file.txt)" << endl << "allow every one enter? enter disable(for no) and enable(for yes)" << endl;
		string allow;
		int end=0;
		while(end!=1){
			cin >> allow;
			if(allow==blah1){
				File << "allow?" << endl << "enable";
				end = 1;
				system("exit");
			}else if(allow==blah2){
				File << "allow? \n";
				File << "disable";
				end = 1;
				system("exit");
			}else{
				cout << "sorry what? please enter again" << endl;
			}
		}
		first << "not";
		first.close();
	}	
	string canIS;
for(int i =1; i<=2;i++){
	getline(File, canIS, '\n');
}

if(canIS=="enable"){
	cout<<"hey you hit the second line ";
cout << canIS;
} else {
	cout << "sorry the admin do not allow to you";
}

    int blah;
	cin >> blah;
}

its dosent write anything in the text documents
thx anyway

you're going to want to compare strings differently.

If you want to compare the contents of two different strings the format is as follows:

string firstTime;//declaration
getline(first, firsttime);

if( firstTime.compare(stringToCompareWith)==0)
{
   //code to execute
}

you're going to want to compare strings differently.

If you want to compare the contents of two different strings the format is as follows:

string firstTime;//declaration
getline(first, firsttime);

if( firstTime.compare(stringToCompareWith)==0)
{
   //code to execute
}

could you give me an example on my code becuase i dont understand some stuff
like the ==0 i did it like so

}else if(allow.compare(blah2)==0){
				File << "allow? \n";
				File << "disable";
				end = 1;
				system("exit");
			}

and its still the same

I took a quick look, and as far as I can tell, your program can't get past line 33 because the only way out of your while loop is via system("exit") (which I didn't even think about until just now, and appears to kill off the CommandPrompt that your program is apparently running in. Probably not really the best approach, and besides there's still no way to set the your firsttime string to "not".

As far as not writing anything into the file, it may be your strategy for terminating the program is brute-force killing it off before it has a chance to flush output buffers to the disk. Try something simple like "return 1;" for an error condition or "return 0;" for success, instead of "system("exit");"

I took a quick look, and as far as I can tell, your program can't get past line 33 because the only way out of your while loop is via system("exit") (which I didn't even think about until just now, and appears to kill off the CommandPrompt that your program is apparently running in.

No. system() starts a new shell (which in turn executes exit command and immediately exits). Essentially system("exit") is a very expensive no-op.

I took a quick look, and as far as I can tell, your program can't get past line 33 because the only way out of your while loop is via system("exit") (which I didn't even think about until just now, and appears to kill off the CommandPrompt that your program is apparently running in. Probably not really the best approach, and besides there's still no way to set the your firsttime string to "not".

As far as not writing anything into the file, it may be your strategy for terminating the program is brute-force killing it off before it has a chance to flush output buffers to the disk. Try something simple like "return 1;" for an error condition or "return 0;" for success, instead of "system("exit");"

i did it like that

if(allow==blah2){
				File << "allow? \n";
				File << "disable";
				end = 1;
				return 0;

and its quiting the program once i enter disable/enable

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.