cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
File Manipulation in C++, is what I have
File Manipulation in C++, is what I have so far ok?
May 11, 2009 at 8:05pm UTC
steinzfan
(43)
Here is my code, I'm trying to allow the user to input a path to a text file. It reads it, stores it, allows the user to input more data INTO the stored file, and also display what is stored on the console in it's entirety:
void LoadTextFile()
{
string filePath;
cout << "Enter a file path:"\n;
cin >> filePath;
ifstream inFile(filePath);
while (inFile.peek() != EOF) {
string inLine;
getline(inFile, inLine);
cout << inLine << endl;
}
inFile.close();
return 0;
}
how do I refer to what is stored now in order to add to it and/or display it on the console?
May 11, 2009 at 8:16pm UTC
Duthomhas
(13206)
You never
stored
anything -- you only read each line and echoed it to the console.
I suggest using a
vector
of
string
to store the content of the file.
Hope this helps.
Topic archived. No new replies allowed.