#include<iostream>
#include<fstream>
#include<limits>
usingnamespace std;
int main()
{
string c, s, t, u, b;
bool a = true;
cout << "Welcome to the Address Book! ";
cout << "What will you call your text file? ";
cin >> c;
ofstream streamone('c', ios::app);
do
{
cout << "Enter a person's first and last name. ";
cin >> s >> t;
cout << "Input their full address (ex. 123 Road Rd. Boston, MA). ";
getline (cin, u);
getline (cin, u);
cout << "Enter their phone number: ";
cin >> b;
streamone << s << " " << t << endl;
streamone << u << endl;
streamone << b << endl << endl;
}
while(a);
streamone.close();
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
cout << "Press Enter to exit this program...\n";
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' );
}
I'm wondering how to let the user input the text file's name (lines 11-13), but I got an error involving changing c "FROM CHAR TO CONST CHAR". Any ideas?
#include<iostream>
#include<fstream>
#include<limits>
usingnamespace std;
int main()
{
string c, s, t, u, b;
bool a = true;
char d;
system("TITLE Address Book Maker");
for(int i = 0; i < 1; i++)
{
cout << "Welcome to the Address Book Maker! ";
cout << "What will you call your Address Book file? \n(note: you MUST type \".txt\" at the end and no spaces (you may edit this directly later)!) ";
cin >> c;
cout << "Excellent! ";
do
{
cout << "Now, enter a person's first and last name. ";
cin >> s >> t;
cout << "Input their full address (ex. 123 Road Rd. Boston, MA (insert zip code here)). ";
getline (cin, u);
getline (cin, u);
cout << "Enter their phone number: ";
cin >> b;
ofstream streamone(c.c_str(), ios::app);
streamone << s << " " << t << "'s address is" << endl;
streamone << u << " and his phone number is" << endl;
streamone << b << "." << endl << endl;
cout << "The program will show this:\n" << s << " " << t << "'s address is" << endl << u << " and his phone number is" << endl << b << "." << endl << endl;
do{
cout << "Restart? (y or n) ";
if(d == 'y' || d == 'Y')
continue;
elseif(d == 'n' || d == 'N')
a = false;
}while (d != 'y' && d != 'Y' && d != 'n' && d != 'N');
streamone.close();
}while(a);
}
return 0;
}
Right after 26, an infinite loop starts, for no visibly apparent reason. Any ideas?