C++ GetString function help Function reads string from file and returns it strin
ID: 3793503 • Letter: C
Question
C++ GetString function help Function reads string from file and returns it string GetString(ifstream &inData);String GetString(ifstream &inData) { String newString;
Return newString; } C++ GetString function help Function reads string from file and returns it string GetString(ifstream &inData);
String GetString(ifstream &inData) { String newString;
Return newString; } C++ GetString function help Function reads string from file and returns it
String GetString(ifstream &inData) { String newString;
Return newString; }
Explanation / Answer
Solution for the Problem(C++):-
Program:-
#include <iostream>
#include <fstream>
#include<string>
using namespace std;
string GetString(std::ifstream &inData)
{
string newString;
// myReadFile.open("text.txt");
if (inData.is_open())
{
// while (!inData.eof())
{
inData >> newString;
}
}
return newString;
}
int main () {
std::ifstream myfile;
myfile.open ("example.txt");
string a=GetString(myfile);
cout<<a<<endl;
myfile.close();
return 0;
}
Output:-
Writing
//Writing is the first string in the file
Note:- If you want to write entire file then activate the while loop and print their it self.To print entire file other wise only files last string only returns to the main function.
Thank you!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.