Hello everyone I am currently just trying to figure out why when I input write instead of read in the program it outputs the same string twice. I mean the code works its just really annoying me and I can't for the life in me figure out why it bis behaving in such a manner.
any tips would be appreciated
cout<< "what would you like to do today? read or write a file: "; this line outputs twice when I enter write
void pencil::write()// this will create a new file and allow you to input numbers into it
{
string input;
ofstream outputFile;
float num1 = 0;
cout << "what is the name of the file with extention you want to create?: ";
getline(cin, input);
outputFile.open(input.c_str());
while (num1 != -1)
{
cout << "Enter the number: (enter -1 to end): ";
cin >> num1;
cin.ignore();//-------------------------------------------add this
if (num1 != -1)
outputFile << num1 << endl;
}
outputFile.close();
}