how to get input fromtext file to c++source progarm

Write your question here.

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<fstream.h>
#include<graphics.h>
void input();
void output ();
struct dom
{
int date;
int month;
int year;
};
struct reg
{
int nos;
char a[3];
};
struct chasno
{
reg chs;
};
struct engno
{
reg engno;
};
struct ve
{
engno e1;
chasno e2;
reg e3;
dom domm;
char model[12];
char clo[10];
int hrspwr;
int sitcap;
};
struct truck
{
ve bsc;
int ldngcap;
int nowhel;
};
void main ()
{
char q;
do
{
clrscr();
ve car,bike;
truck truck1;
int a;
cout<<"==============******************* Welcome ******************====================\n";
scores.txt format
James J Jones 80
Mike M Martin 95


File input example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <fstream>

int main()
{
	std::ifstream input;

	// Open a file
	input.open("scores.txt");
	
	//If file fails exit
	if (input.fail())
		return 1;

	// Read data
	char firstName[80];
	char mi;
	char lastName[80];
	int score;
	input >> firstName >> mi >> lastName >> score;
	std::cout << firstName << " " << mi << " " << lastName << " "
		<< score << std::endl;

	input >> firstName >> mi >> lastName >> score;
	std::cout << firstName << " " << mi << " " << lastName << " "
		<< score << std::endl;

	input.close();

	std::cout << "Done" << std::endl;
	return 0;
}
Topic archived. No new replies allowed.