I am trying to get a whole line from user and write into an array of char's
but it doesn't work.
what do i use?
i know 'cin' stops as soon as there is a space in the string..
i've tried:
Code:getline(cin, variable);
// I GET AN ERROR^
Printable View
I am trying to get a whole line from user and write into an array of char's
but it doesn't work.
what do i use?
i know 'cin' stops as soon as there is a space in the string..
i've tried:
Code:getline(cin, variable);
// I GET AN ERROR^
:confused:Code:/************************************************** ****
Get a whole line and write to an array
************************************************** ****/
#include <iostream>
#include <string.h>
#include <math.h>
#include <ctype.h>
int print_out(char[],int);
using namespace std;
int main()
{
char array[81];
char write_array[81]; // the new array you wanna write to
cin.getline(array,81);
int size_of=strlen(array);
for (int a=0; a<size_of; a++)
{
write_array[a]=array[a];
}
print_out(write_array,size_of);
int stop;
cin>>stop;
}
//Declare function print out
int print_out(char write_array[],int size_of)
{
cout<<"The array is:";
for (int a=0; a<size_of; a++)
{
cout<<write_array[a];
}
}
Have you actually declared 'variable' as an std::string or char array?Quote:
Originally Posted by mrafcho001
Lithorein Yes
I got it working.. i wasn't sure what it was..
cin.getline() works perfectly thanks