Displaying Vectors

Hello! I'm attempting to create a program that takes a phrase and displays only the first word, by putting it into a vector and then displaying the vector. When I run the program, I get the intended word followed by a bunch of characters, and I can't figure out why. If anyone could enlighten me on what I'm doing wrong, I'd really appreciate it. Thank you!

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
#include <iostream>
#include <string.h>
#include <cctype>
#include <fstream>
#include <vector>
#include <windows.h>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main()
{
    string input;
    vector<char> word;
    getline (cin, input);
    int counter = 0;
    for (int i=0; i<=input.length()-1; i++)
    {
        char c = input[i];
        if (isspace(c))
            break;
        else
            word.push_back(c);

    }
    for (int i = 0; i<=sizeof(word)-1; i++)
    {cout << word[i] ;}
    return 0;
}
I just realized that I created a bunch of different objects within the vector. I only need to create one. Any idea as to how I would do that?
for (int i = 0; i<=sizeof(word)-1; i++)
should be:
for (int i = 0; i<=word.size()-1; i++)
or more commonly:
for (int i = 0; i < word.size(); i++)
Thank you! I figured a way around it. I've managed to get stuck elsewhere, however
Topic archived. No new replies allowed.