I have made a if statement, and I know that it is carried through because the first cout in it is executed, and one I put at end to test.
Code:using namespace std; //namespace std int i; string line; //initiate a string vector<string> names; int main () { char string[256]; std::string user_input; cout<< "Enter one to add name, or zero to continue: "; cin>> i; if (i == 1) { cout<< "please enter name: \n"; cin.getline(string, 256); user_input = string; ofstream people ("example.txt", ios::app); //open file people<< "\n" << user_input; //write names people.close(); //close file, so it can be opened in read mode i = 0; cout<< "test" // comes throuch cin >> i; /// executes. }
Whats wrong with the program?