why cant i type in my address???

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int maxstring = 120;
typedef char stringtype[maxstring];

void newuser(){
     system ("cls");
     stringtype name;
     string type, id, cnumber, address;
     double amount;
     
     ofstream out;
     
     cout << "ENTER YOUR NAME: ";
     cin >> name;
     out.open(name, ios::out);
     out << "USERNAME/NAME : " << name << endl;
     
     cout << "ENTER IDENTITY CARD NUMBER: ";
     cin >> id;
     out << "IDENTITY CARD NUMBER : " << id << endl;
     
     cout << "ENTER YOUR ACCOUNT TYPE(current/savings): ";
     cin >> type;
     out << "ACCOUNT TYPE : " << type << endl;
     
     cout << "ENTER YOUR CONTACT NUMBER: ";
     cin >> cnumber;
     out << "CONTACT NUMBER : " << cnumber << endl;
     
     cout << "ENTER YOUR ADDRESS: ";
     cin >> address;
     out << "ADDRESS : " << address << endl;
     
     cout << "AMOUNT TO BE DEPOSITED: ";
     cin >> amount;
     out << "AMOUNT DEPOSITED: RM" << amount;
     
     out.close();
}

int main(void){
    newuser();
           
       return 0;    
}

>> cin >> address;
The >> operator does not accept spaces. So if your address contains spaces it will pick up only the text before the first space. Use getline() to get everything including spaces.

Change cin >> variable to cin.getline(variable) And use full words in English as the Rules specify. You did read them, didn't you?

Change cin >> variable to cin.getline(variable) And use full words in English as the Rules specify. You did read them, didn't you?

I think most compilers will give you an error if you don't specify the number of characters to input (at least mine does).

cin.getline(szVariable, iNumberOfLetters);

it doesn't work...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int maxstring = 120;
typedef char stringtype[maxstring];

void newuser(){
     system ("cls");
     stringtype name;
     string type, id, cnumber, address;
     double amount;
     
     ofstream out;
     
     cout << "ENTER YOUR NAME: ";
     cin >> name;
     out.open(name, ios::out);
     out << "USERNAME/NAME : " << name << endl;
     
     cout << "ENTER IDENTITY CARD NUMBER: ";
     cin >> id;
     out << "IDENTITY CARD NUMBER : " << id << endl;
     
     cout << "ENTER YOUR ACCOUNT TYPE(current/savings): ";
     cin >> type;
     out << "ACCOUNT TYPE : " << type << endl;
     
     cout << "ENTER YOUR CONTACT NUMBER: ";
     cin >> cnumber;
     out << "CONTACT NUMBER : " << cnumber << endl;
     
     cout << "ENTER YOUR ADDRESS: ";
     cin.getline(address, 100);
     out << "ADDRESS : " << address << endl;
     
     cout << "AMOUNT TO BE DEPOSITED: ";
     cin >> amount;
     out << "AMOUNT DEPOSITED: RM" << amount;
     
     out.close();
}

int main(void){
    newuser();
           
       return 0;    
}

http://img174.imageshack.us/my.php?image=87777423aw2.jpg

That form of cin.getline() only works with character arrays, not std::string objects. To use string do this instead. getline(cin, address)

it compiles but it skips the cin address part...

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

const int maxstring = 120;
typedef char stringtype[maxstring];

void newuser(){
     system ("cls");
     stringtype name;
     string type, id, cnumber, address;
     double amount;
     
     ofstream out;
     
     cout << "ENTER YOUR NAME: ";
     cin >> name;
     out.open(name, ios::out);
     out << "USERNAME/NAME : " << name << endl;
     
     cout << "ENTER IDENTITY CARD NUMBER: ";
     cin >> id;
     out << "IDENTITY CARD NUMBER : " << id << endl;
     
     cout << "ENTER YOUR ACCOUNT TYPE(current/savings): ";
     cin >> type;
     out << "ACCOUNT TYPE : " << type << endl;
     
     cout << "ENTER YOUR CONTACT NUMBER: ";
     cin >> cnumber;
     out << "CONTACT NUMBER : " << cnumber << endl;
     
     cout << "ENTER YOUR ADDRESS: ";
     getline(cin, address);
     out << "ADDRESS : " << address << endl;
     
     cout << "AMOUNT TO BE DEPOSITED: ";
     cin >> amount;
     out << "AMOUNT DEPOSITED: RM" << amount;
     
     out.close();
}

int main(void){
    newuser();
           
       return 0;    
}

http://img72.imageshack.us/my.php?image=63886930ku6.jpg

You have to flush the cin buffer first. Use:

cin.ignore(cin.rdbuf()->in_avail());

Usually you should put this line after any sort of keyboard input to make sure there's no characters left in the input buffer that will get used in the next statement(s).

The keyboard buffer must still have the return character in it, causing a false positive to occur when getline is searching for the end of input.

thank ancient dragon....it worked.....i have another question how do u read one word at a time from a text file???

use the fstream's >> operator, exactly as you already posted in your program using cin to get the name.

ifstream in("filename");
string word;
while( in >> word)
{

}

thanks man...it works....i'll b having more questions later....can i pm u???....thanks again....

This question has already been answered. Start a new discussion instead.