-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspp53_Library.h
63 lines (53 loc) · 1.18 KB
/
spp53_Library.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//Stevie Parris version 1.0
//Revision History:
//Created February 25, 2014 : added promptForString function - include iostream/string
#ifndef
#include <string>
#include <iostream>
using namespace std;
static string promptForString(string prompt); //prototype
static string promptForString(string prompt) // function that asks user for string and returns it
{
cout << prompt << endl; // print the user prompt
string input;
getline(cin, input); //store user's string
return input;
}
bool createNewFile(ofstream& out, string filename)
{
bool test = false;
string input;
fstream fin;
fin.open(filename.c_str(), ios::in);
if(fin.is_open())
{
fin.close();
test = true;
}
fin.close();
if(test == true)
{
cout << "A file with this name already exists. \n Would you like to overwrite this file? (y or n)\n";
cin >> input;
if(input == "n")
{
cout << "Would you like to cancel or change the name of the file? (c or n)\n";
cin >> input;
if (input == "n")
{
cout << "Enter a new filename: \n";
cin >> filename;
out.open(filename);
return true;
}
}
}
else
{
ofstream myfile;
out.open(filename);
return true;
}
return false;
}
#endif