So I'm really stuck trying to figured this bug on the program that is preventing me from displaying the text of my program..
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>
#include <stdio.h>
using namespace std;
int main ()
{
ifstream infile;
ofstream offile;
char text[1024];
cout <<"Please enter the name of the file: \n";
cin >> text;
infile.open(text);
string scores; // this lines...
getline(infile, scores, '\0'); // is what I'm using...
cout << scores << endl; // to display the file...
// Is there any way cleaner or simple method i can used to display the file ?
//All the method in the internet are difficult to understand or keep track due to the file is open in loop..
//I want a program that you type the name of the file and displays the file
// the file will contain the following...
// jack 23
//smith 27
//also I need to obtain data from the file
//now I'm using the following code to obtain that information from the file...
string name1;
int name2;
string name3;
int name4;
infile >> name1;
infile >> name2;
infile >> name3;
infile >> name4;
cout << "these two individual with their age add are" << name2 + name4 <<endl;
// 23 + 27
//the result I get is a bunch of numbers...
return 0;
}
> Is there any way cleaner or simple method i can used to display the file ?
std::cout << std::ifstream( "name_of_the_file.txt" ).rdbuf() ;