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;
}

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';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.