Hi, imnewbie to c++ programming. Im want to read some txt file that have a data write inside. The data should be "WAT1235" which is the license plate number. Then if the programming read this data "WTA1234" it will give other information like the Roadtax, Colour of the car and etc. I want to display the output should be like :

OUTPUT DISPLAY:

WTA1235
Information:
Roadtax:.....
ModelCar:.....
etc..

This my coding for the fisrt step read the txt file, but have some error

Inline Code Example Here
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void main(){

    ifstream inFile;
    inFile.open("test.txt");

    //Check for Error
    if (inFile.fail()){
        cerr << "Error Opening File" << endl;
        exit(1);
    }
    return 0;
}

Any suggestion and discuss will very helpfull.

Recommended Answers

All 2 Replies

void main(){ has never ever ever been correct. int main(){ is.

For your code to work, the executable needs to be in the same directory as the text file you're trying to open. Is it? How do you know?

what exactly is the error? compiler error? runtime erro? you get the "6rror opening file" message in your program?

You also need to tell us what compiler and operating system you are using.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.