Hi guys, first off i'm trying to Write a program that reads a series of strings into a vector and then prints out a string with all elements concatenated, with each element separated with a "-". So if the input is "hello world" then your proram should output "hello-world".
This program doesn't seem too hard at first glance and below is my current progress. I'm only on chapter 3 of my book so this program shouldnt be overly complicated. What is getting me confused it the book does a poor job explaining how to treat and munipulate the data inside the vector. Once the series of strings is loaded into the vector can we still treat the data as if they were strings.
My thought process behind this would be the same way as I would replace printable whitespace with a "-" character by going through the data located within the string one char at a time but that doesn't seem to be working.
I guess my real question is what is the best way to treat the strings located inside the vector. Any help or suggestions is greatly appreciated.
Code:
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
using std::cin ;
using std::cout;
using std::string;
using std::vector;
int main(){
vector<string> text() ; //empty vector
cout << "Please enter a string" ;
while( cin >> text){ //append word to text
text.push_back(word);
// This is the part thats throwing me for loop below (no pun intended)
for( vector<string> :: size_type index = 0 ; index != text.size(); ++index)
{
if ( isspace(text[index])){
cout << "-" ;
}else {
cout << text[index] ;
}}