Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream> //exercise 6
- #include <string> //find the longest word in sentence which ends with '.'
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream in("input.txt");
- ofstream out("output.txt");
- string maximum;
- string s;
- while(in >> s)
- {
- if (s[s.length() - 1] == '.' || s[s.length() - 1] == ',' || s[s.length() - 1] == ':' || s[s.length() - 1] == ';' || s[s.length() - 1] == '!' || s[s.length() - 1] == '?' || s[s.length() - 1] == '(' || s[s.length() - 1] == ')' || s[s.length() - 1] == '-')
- s.erase(s.length() - 1);
- if (s.length() > maximum.length())
- maximum = s;
- }
- out << maximum;
- in.close();
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment