I am currently trying to learn C++ and I'm working on my first project. It is supposed to ask questions and get the user to provide the input for the answer then write the input to a file with some formatting. however, I keep getting an error with the description line input, it takes the first word in a sentence and nothing else. I've tried several things to get it to work and all of them throw a similar error or don't allow me to give any input...
cin >> description; allows me to give input of 1 word.
std::getline and getline dont allow me to give any input.
I just seem to get these errors:
Error (active) E0304 no instance of overloaded function "std::basic_istream<_Elem, _Traits>::getline [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list
or this error:
std::basic_istream<char,std::char_traits<char>>::getline': non-standard syntax; use '&' to create a pointer to member
My current code looks like this:
int main()
{
ofstream myfile;
myfile.open("Output.txt");
if (myfile.is_open())
{
cout << "Enter kit name\n";
cin >> kit;
myfile << " \"" << kit << "\":{\n";
cout << "Default Amount?\n";
cin >> defaultamount;
myfile << " \"DefaultAmount\":" << defaultamount << ",\n";
cout << "Price\n";
cin >> price;
myfile << " \"Price\":" << price << ",\n";
cout << "Enter a Description for the kit\n";
cin >> description;
myfile << " \"Description\":\"" << description << "\",\n";
myfile.close();
cout << "output.txt has been updated with your results\n";
system("pause");
}
else
cout << "Unable to create or update text file";
return 0;
}