-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexx.cpp
More file actions
54 lines (37 loc) · 1.13 KB
/
Copy pathindexx.cpp
File metadata and controls
54 lines (37 loc) · 1.13 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
51
52
53
54
#include <iostream>
#include <fstream>
// fstream class provides input and output operations like istream nd ostream
#include <string>
using namespace std;
int main()
{
// welcome
cout << "Welcome to my Project - Word Count" << endl << endl;
// declaring and inputing File name
string filename;
cout << "Enter the name of your file : ";
cin >> filename;
cout << "\n";
ifstream inFile(filename.c_str());
// c_str() function is used to convert a string to a C-style string(array of chars)
if (!inFile.is_open())
{
cerr << "Sorry! The File " << filename << " you opened may not exist. \n"
<< endl;
// cerr is the cout for errors
return 1;
}
// inFile.open ("Countcpp.txt" , ios::in);
// open() - Opens the file to perform i/o operations
int wordCount = 0;
string words;
while (inFile >> words)
// or getline(inFile,words)
{
++wordCount;
}
cout << "The total word counts in your file " << filename << " are : " << wordCount << endl << endl;;
inFile.close();
cout << "Thankyou ! Try next :)";
return 0;
}