read file problem.

i need a help on how to read a space in a txt file.
my output now is
1
2
3
012-3456789
fernandinho
silva

i have problem in how to read a space between the name.

1
2
3
4
5
6
7
8
9
10
  ifstream file1;
    void getrecord(){      
        file1.open("record.txt");
        file1 >> telno;
        file1 >> name;     
        file1 >> adress;

        cout << telno << endl;
        cout << name << endl;
        cout << adress ;



my txt file.
1
2
3
4
5
6
012-3456789
fernandinho silva
Manchester City
987-6543211
joseph steven john
chelsea london.

closed account (48T7M4Gy)
You need to use std::getline (file1,name); for the lines where spaces are not delimiters between separate values but just part of the full string value
Last edited on
 
getline(file1,name,'\n');


yup, thank you. it work now.
Topic archived. No new replies allowed.