Yes. This is possible.
There are some facts to consider though. The cin object reprsents the standard input as a stream. It extracts the characters from the input stream that we generate at the keyboard.
">>" is an extraction operator. As the name implies, if we apply this on cin it removes the read characters from cin and returns it. And when we apply this extraction operator to string(or char array), it extracts only one word at a time. So we use "get" and "getline" member functions to read one line.
In your example, before passing the reference to your test function, you extract the value. So we can not get that value again in the test method. Some members of cin like peek() reads the character from cin without extracting. But we can use that only for reading one character(the next character in the cin).
Having said this, the following code might be helpful to you. It reads a string of atmost 99 characters and prints that out. The additional one character in the array is used for the terminating character.
#include <iostream>
using namespace std;
void test (istream &input);
int main(){
cout << "Input the string: ";
test(cin);
return 0;
}
void test (istream &input)
{
char a[100];
cin.getline(s, 100);
cout << a;
}
In this code I have used getline to read a whole line. We can use the operator << in a loop but it skips over white spaces. Depending on the usage you can choose either of this.