basic input and output problem

I am new to c++, I just start to learn programming from yesterday, and I already stuck at a very simple task.
I want to write a program to read a single word from the console and print that word back to the console. I wrote this code, it work but it also print a "0" at the end. I want the program only prints that word to the console with no additional output. How can I do this? pls help me
And sorry for my bad Englsh, I am not a native English speaker.

1
2
3
4
5
6
7
8
9
10
11
  #include <iostream>

using namespace std;

int main ()
{
    int i;
    cin >> i;
    cout <<  i;
    return 0;
}
Hello astropolaris,

A fundamental thing to understand in C++ programming is the concept of types. An int type represents an integer number (-1, 0, 1, 2, 3, ...). A word cannot be stored in an integer. You should use a string type for that. "Strings" are groups of characters in programming terminology.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

using namespace std;

int main ()
{
    string s;
    cin >> s;
    cout << "You typed: " << s;
    return 0;
}

asfd
You typed: asfd 
Last edited on
oh, I understand now, thank you very much!
Topic archived. No new replies allowed.