-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnc475_Library.h
65 lines (51 loc) · 1.06 KB
/
nc475_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
64
65
/*
File: nc475_Library.h
Author: Nischaal Cooray
Date: 2014/02/24
Version: 1.0
*/
/* Copyright 2014 Nischaal Cooray*/
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <fstream>
#pragma once
using namespace std;
/*
Prompts the user for specific input and returns the input string to the calling program.
@param Prompt: the string to be displayed to the user to request specific input
@return: the string entered by the user after the prompt
*/
static string promptForString(string Prompt)
{
string userInput;
cout << Prompt;
cin.ignore();
getline(cin, userInput);
return userInput;
}
bool createNewFile(ofstream& out, string filename)
{
ifstream fin;
fin.open(filename);
int userAnswer;
if (fin.good())
{
cout << "The file " << filename << " already exists." << endl;
cout << "Do you want to overwrite it or cancel? (1 for overwrite, 2 for cancel): ";
cin >> userAnswer;
if (userAnswer == 1)
{
out.open(filename);
return true;
}
else
return false;
}
else
{
out.open(filename);
return true;
}
}