Yes, the point of the input loop is that input is terminated when EOF is encountered (Ctrl+Z on Windows). Works also nicely if stdin is redirected to a file.
Below is what a program that does exactly the same would look like when you take advantage of what the standard libraries offer.
Code:
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
//I actually don't see much point in doing this for things that you are going to use once.
//just typing std::sort once or twice in the code is a lot simpler
using std::string; using std::cout;
using std::cin; using std::vector;
using std::endl; using std::sort;
//it is useful to separate code with a specific task into a separate function for ease of reuse
//a ready-made function by this name also exists in the Boost.StringAlgorithm library
string join(const vector<string>& source, const std::string& delimiter)
{
string concatenated;
if (!source.empty()) {
concatenated = source[0];
for (vector<string>::size_type i = 1; i != source.size(); ++i) {
concatenated += delimiter + source[i];
}
}
return concatenated;
}
int main()
{
cout<<"Please input a sentence: ";
vector<string> inpVecStr;
string input;
while(cin>> input)
inpVecStr.push_back(input);
vector<string> indexedVec;
if (!inpVecStr.empty()) {
//store the first unrotated "sentence"
indexedVec.push_back(join(inpVecStr, " "));
//rotate input.size() - 1 times (rotating one more time would produce the original input)
for (vector<string>::size_type i = 1; i < inpVecStr.size(); ++i)
{
//unless for learning purposes, always prefer a suitable STL algorithm over hand-rolled loop
//this rotates everything by one position to the left
std::rotate(inpVecStr.begin(), inpVecStr.begin() + 1, inpVecStr.end());
indexedVec.push_back(join(inpVecStr, " "));
}
//print all rotations :)
std::copy(indexedVec.begin(), indexedVec.end(), std::ostream_iterator<string>(cout, "\n"));
}
return 0;
}