Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<string>
- using namespace std;
- int main()
- {
- int nWords = 0;
- ofstream outFile;
- outFile.open("Output.txt");
- ifstream inFile("Lab5_1Input.txt");
- if (inFile.fail()) {
- cerr << "File Failed/Not Found" << endl;
- }
- else {
- int wordcount = 0;
- int wordcount_1 = 0;
- string word;
- string item;
- ofstream OutFile;
- cout << "Opened\n\n";
- while(std::getline(inFile, item)) {
- item = item + '\n' + '\r';
- //cout << item;
- outFile << item;
- int i = 0, ans = 0;
- if (item.find(' ', i + 1) != -1)
- {
- i = item.find(' ', i + 1);
- ans++;
- }
- cout << item << ans;
- if (inFile.peek() == '\n' || inFile.peek() == '\r')
- {
- //finding spaces to count words
- int i = 0;
- int ans = 0;
- if (item.find(' ', i + 1) != -1)
- {
- i = item.find(' ', i + 1);
- ans++;
- }
- }
- }
- //cout << item;
- //outFile << " " << ++ans << endl;
- }
- inFile.close();
- outFile.close();
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement