I'm supposed to create a program to read in word by word into a vector. And print out the words connected with '-'... so if the input was hello world the output would be hello-world

this is the code ive made so far... right now my input can be hello world but my output would be
hello-
world-

i dont want the - after world and i want it printed out on one line... any help would be appreciated.

#include <iostream>
#include <iomanip>
#include <vector>

using namespace std;
using std::vector;

int main()
{
  vector<string>svect;
  string word;
  while( cin >> word ){
    word += '-';
    svect.push_back(word);
  }

  for( int i = 0; i < svect.size(); i++ )
    cout << svect[i] << endl;

  return 0;
}

Edited 7 Years Ago by Dewey1040: n/a

don't add the '-' until the words are printed out at lines 18 and 19. Then print two words at a time with the '-' between then.

for( int i = 0; i < svect.size(); i += 2 )
    cout << svec[i] << '-' << svec[i+1] << '\n';
This question has already been answered. Start a new discussion instead.