Wednesday, March 15, 2017

C++ Part 23

Using Getline

Reading From a Text File Using ifstream:

To read from a text file we need to include the fstream library and create an ifstream object which is placed in the std namespace.


#include <fstream>
using namespace std;  


Example


//NavidPlus.blogspot.com
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main( )
{
   string Name, Website;
   string description;
   fstream inputStream;
   inputStream.open("Website");

   inputStream >> Name >> Website;
   inputStream >> description;
   cout << "Name: " << Name << "      "  << "Website: " << Website << endl;
   cout << "description: " << description << endl;
   inputStream.close();
   return 0;
}

The input file is Website and must be in the same folder


NavidPlus https://NavidPlus.blogspot.com
NavidPlus@Blogger


No comments:

Digital Design Part 3

4th→ assembler translates it to the machine language. 1.6 [20] <§1.6> Consider two diļ¬€erent implementations of the same instru...