+ Reply to Thread
Results 1 to 2 of 2

Thread: How to read a input text file line by line using ifstream object?

  1. #1

    How to read a input text file line by line using ifstream object?

    How to read a input text file line by line using ifstream object in C++?

    Please provide some small example.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    24
    Code:
    void ReadFile()
    {
    	std::ifstream inputFile("C:\\Input.txt") ;
    
    	if (inputFile.is_open())
    	{
    		std::string strLine ;
    		while (inputFile.good())
    		{
    			getline (inputFile, strLine) ;
    			printf(strLine.c_str()) ;
    			printf("\n") ;
    		}
    		inputFile.close() ;
    	}
    }
    Use above example code to read a input text file line by line.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts