-3

I am trying to print missing alphabets in given string. The input specification is to end string input if user enter "endpara". With my current code it is storing only first word in string even though input is terminating after entering 'endpara'. (for eg. if I enter "fox jumps over a. endpara" , it is storing only fox in string. How can I store entire string before endpara?

#include<bits/stdc++.h> 
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std; 
    const int MAX_CHAR = 26; 

    string missingChars(string str) 
    { 
        bool present[MAX_CHAR] = {false}; 
        for (int i=0; i<str.length(); i++) 
        { 
            if (str[i] >= 'a' && str[i] <= 'z') 
                present[str[i]-'a'] = true; 
            else if (str[i] >= 'A' && str[i] <= 'Z') 
                present[str[i]-'A'] = true; 
        } 
        string res = ""; 
        for (int i=0; i<MAX_CHAR; i++) {
            if (present[i] == false) 
                res.push_back((char)(i+'a'));} 
         for(int i=0;i<=res.length();i++) { 
            if(res[i]>=97 && res[i]<=122)
            {
                res[i]=res[i]-32;
            }
        }
        return res; 
    } 

    int main() 
    { 

       string input;
       string line;
        while (getline(cin, input) && input != "endpara") {
        istringstream is(input);
        is>>input;
        if(missingChars(input)== ""){
            cout<<"NONE";
        }
        else{
            cout<<missingChars(input);
        }
        }
        return 0; 
    } 
  • 2
    https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h –  Aug 03 '19 at 17:10
  • 2
    **Recommended reading:** [Why should I not #include ?](https://stackoverflow.com/q/31816095/560648) – Lightness Races in Orbit Aug 03 '19 at 17:25
  • You check if a whole line is exactly that word. You might want to take a look at `std::string::find`. Or to delimit that line before you go on. By the way, keep your example minimal - we don't need to know what `missingChars` is to help you. Simply omit that part. – Aziuth Aug 03 '19 at 17:31

1 Answers1

1

The problem is that you only take input once inside your loop:

istringstream is(input);
is>>input;

You need to loop through the string stream until the end of the stream:

istringstream is(input);
while(is>>input) {
    if(...) {
        // ...
    } else {
        // ...
    }
   // etc
}