#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
constint ARRAY_SIZE = 200;
string movieTitle [ARRAY_SIZE];
string movies;
int loadData (string pathname);
int getTitle (string movies);
void showAll (int count);
int main()
{
loadData("movies.txt");
char userInput;
string movieTitle[ARRAY_SIZE];
int count = getTitle(movies);
bool endOfProgram = false;
while (endOfProgram ==false)
{
cout << "1. Read in Collection" << endl;
cout << "2. Print Collection" << endl;
cout << "3. Add a Movie to the Collection" << endl;
cout << "4. Write out Collection" << endl;
cout << "5. Quit the Program" <<endl;
cin >> userInput;
switch(userInput)
{
case('1'):
{
loadData(movies.txt);
break;
}
case('2'):
{
showAll(loadData(movies.txt));
break;
}
case('3'):
{
cout <<"Add Movies to the Collection. Press (q) to quit"<< endl;
cin >> movieTitle;
}
case('4'):
{
cout <<"Write out Collection" << endl;
outfile.open ("movies.txt");
if(!outfile.is.open())
{
cout <<"Cannot open movies.txt" << endl;
return -1;
}
outfile.close();
}
case('5'):
{
endOfProgram=true;
cout << "Have a nice day" <<endl;
break;
}
}
int loadData (string pathname)
{
int count = 0;
ifstream inFile;
inFile.open(pathname.c_str());
if (!inFile)
return -1;
else
{
while(!inFile.eof())
{
getline(inFile, movieTitle[count]);
count++
}
}
return count;
}
void showAll (int count)
{
cout << "\n";
for (int i=0; i< count; i++)
{
cout << movieTitle[i] << endl;
}
cout << "\n";
}
int getTitle (string movies[]);
{
string movieTitle
int count = 0;
while(true)
{
cout <<"Enter Movie Titles (Type 'q' to quit)" <<endl;
cin >> movies;
if (movies == "q")
{
break;
}
movies [count] = movies;
count++;
}
return count;
}
void printMovies(const string movies [], int count)
{
for(int i=0; i<count;i++
{
cout <<movies[i] <<endl;
}
}
These are the error messages I am receiving:
36 21 C:\Users\MyName\Documents\Class\Project\project5c++.cpp [Error] 'std::string' has no member named 'txt'
42 29 C:\Users\MyName\Documents\Class\Project\project5c++.cpp [Error] 'std::string' has no member named 'txt'
48 9 C:\Users\MyName\Documents\Class\Project\project5c++.cpp [Error] no match for 'operator>>' (operand types are 'std::istream {aka std::basic_istream<char>}' and 'std::string [200] {aka std::basic_string<char> [200]}')
I'd sincerely appreciate any and all help, or just a point in the right direction. Thanks so much.
The name of the variable is movies not movies.txt. With movies.txt you are trying to access a member of the string named txt which does not exists. You might want the string "movies.txt". That's different.
Something like this movies [count] = movies; does not make sense. Either movies is an array or not. Both is not possible. In your case movies is not an array.