-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileProcessor.cpp
More file actions
50 lines (39 loc) · 1.31 KB
/
Copy pathFileProcessor.cpp
File metadata and controls
50 lines (39 loc) · 1.31 KB
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
/*
Derek Norman
2364922
norman@chapman.edu
CPSC-350-03
Assignment 4
*/
/*
* class called FileProcessor and takes an input file and returns a string of the first line from the txt file
*/
#include "FileProcessor.h"
FileProcessor::FileProcessor() { //constructor
}
FileProcessor::~FileProcessor() { //destructor
}
/*
* This class if file processor, it process a text file given the file path and returns the first line of the text file as a string
* returns a string representing the first line of the file
*/
string FileProcessor::processFile(){
cout << "Please provide file path" << endl;
string filePath;
cin >> filePath;
if(filePath.length() < 4) { //checks if file name length is 3 or less which is not possible with .txt extension
cout << "please use a valid file name with .txt" << endl;
processFile(); //recalls function so user can input correct file
}
else if(filePath.substr(filePath.length() - 4) != ".txt"){ //check if file has .txt extension
cout << "please input a .txt file for the input" << endl;
processFile();
}
string line;
ifstream input(filePath); //opens input fule for reading
if(input.is_open()){ //while input file is open
getline(input, line); //gets the DNA sequence
}
input.close();
return line;
}