Typing a sentence

So I made this and it works, more or less... Although the "." has to be typed independently in order to stop the sentence. Can someone either approve this or post a better more effective method to process a sentence, because I'm sure this one sucks to programming standards...

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
#include <iostream>
using namespace std;

int main ()
{

    cout << "Type a sentence:";

    string sentence[255];
    int counter = 0;

    while(true){
        cin >> sentence[counter];
            if(sentence[counter] == "."){
                break;
            }
        counter++;
    }

    cout << "You just typed:";
    counter = 0;

    while(true){

        if(sentence[counter] == "")
        {
                break;
            }
        cout << sentence[counter] << " ";
        counter++;
    }
        return 0;
}


1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main ()
{
    string sentence;
    cout << "Type a sentence:";
getline(cin,sentence,'.')
 cout << "You just typed: " <<sentence;
return 0;
}
Last edited on
Topic archived. No new replies allowed.