Text Document

I want to create a text document program where I can store info in the text document and recall text I have put into a document already. However, I don't know how to allow for unlimited text input into the document. How would I do this? I don't have much so far, but I'll post it.


#include <iostream>
#include <fstream>

using namespace std;

int main()
{
string filename;
char userinput;
char a = a;
char b = b;

cout<<"Would you like to:\n a) Create a new text document or\n b) Open a previous document?\n";
cin>>userinput;
if (userinput==a)
{
cout<<"File name: \n";
cin>>filename;
ofstream a_file (filename);
cout<<filename<<"is ready for use.\n";
a_file>>
while(getline(cin, linestring) && linestring != "quit") a_file << linestring << '\n'; ?
So this is what I have now, but I'm still getting a bundle of error messages; most are coming from the bolded part.


#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

int main()
{
string filename;
string linestring;
string userinput;
string a = a;
string b = b;

cout<<"Would you like to:\n a) Create a new text document or\n b) Open a previous document?\n";
cin>>userinput;
if (userinput==a)
{
cout<<"File name: \n";
cin>>filename;
ofstream a_file (filename);
cout<<filename<<"is ready for use.\n";
while(getline(cin, linestring) && linestring != "quit")
{
a_file<<linestring<<endl;
}
}
else if (userinput==b);
{
cout<<"File you want to open: \n";
cin>>filename;
ifstream b_file (filename);
b_file>>linestring;
cout<<linestring<<endl;
}
cin.get();
}
The errors in bolded lines are because fstream constructors take char* and you give them std::string. Use std::string::c_str() method. ofstream a_file (filename.c_str());
Topic archived. No new replies allowed.