Advertisement
Guest User

Untitled

a guest
Oct 7th, 2016
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. int nWords = 0;
  12. ofstream outFile;
  13. outFile.open("Output.txt");
  14. ifstream inFile("Lab5_1Input.txt");
  15. if (inFile.fail()) {
  16. cerr << "File Failed/Not Found" << endl;
  17. }
  18. else {
  19. int wordcount = 0;
  20. int wordcount_1 = 0;
  21. string word;
  22. string item;
  23. ofstream OutFile;
  24. cout << "Opened\n\n";
  25.  
  26. while(std::getline(inFile, item)) {
  27. item = item + '\n' + '\r';
  28. //cout << item;
  29. outFile << item;
  30. int i = 0, ans = 0;
  31. if (item.find(' ', i + 1) != -1)
  32. {
  33. i = item.find(' ', i + 1);
  34. ans++;
  35.  
  36. }
  37. cout << item << ans;
  38.  
  39. if (inFile.peek() == '\n' || inFile.peek() == '\r')
  40.  
  41. {
  42. //finding spaces to count words
  43. int i = 0;
  44. int ans = 0;
  45. if (item.find(' ', i + 1) != -1)
  46. {
  47. i = item.find(' ', i + 1);
  48. ans++;
  49.  
  50. }
  51. }
  52.  
  53. }
  54. //cout << item;
  55. //outFile << " " << ++ans << endl;
  56.  
  57.  
  58.  
  59. }
  60.  
  61.  
  62.  
  63. inFile.close();
  64. outFile.close();
  65. getchar();
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement