Guest_imported
New member
- Jan 1, 1970
- 0
Hi! I hope u can help me cause I'm kinda out of ideas.
I want to read from a file some names and store it into an array.
The problem is that the code below reads the whole line. All I want it to do is read the names.
----------THE FILE IT'S READING FROM LOOKS SOMETHING LIKE---
Name 34783
Name2 452894
Name3 3474
Name4 34111323
-------------------------------------------------------
I'm new to this and only know the basics. Keep it simple if u can as it would help alot.
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#define size 10
class List_class
{
private:
char names[size][20];
public:
List_class();
void to_screen ();
};
void main(void){
List_class num_list;
num_list.to_screen ();
} // main
List_class::List_class()
{
fstream infile ("Names.dat", ios::in);
for (int a = 0; a < size; a++){
infile >> names[a];
infile.close();
}
void List_class::to_screen ()
{cout << "This is the list: " << endl << endl;
for (int a = 0; a < size; a++)
cout << names[a] << " ";
}
Thanks guys for the help if you possible. It's greatly appreciated. Thanks a million
I want to read from a file some names and store it into an array.
The problem is that the code below reads the whole line. All I want it to do is read the names.
----------THE FILE IT'S READING FROM LOOKS SOMETHING LIKE---
Name 34783
Name2 452894
Name3 3474
Name4 34111323
-------------------------------------------------------
I'm new to this and only know the basics. Keep it simple if u can as it would help alot.
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#define size 10
class List_class
{
private:
char names[size][20];
public:
List_class();
void to_screen ();
};
void main(void){
List_class num_list;
num_list.to_screen ();
} // main
List_class::List_class()
{
fstream infile ("Names.dat", ios::in);
for (int a = 0; a < size; a++){
infile >> names[a];
infile.close();
}
void List_class::to_screen ()
{cout << "This is the list: " << endl << endl;
for (int a = 0; a < size; a++)
cout << names[a] << " ";
}
Thanks guys for the help if you possible. It's greatly appreciated. Thanks a million