String is not recognized?
Here is my main function:
Code:
/* CSE 231 Project 5 Solution
This file simulates the madlib game by reading a user inputted
file which contains the story line embedded with #XXXX#.
*/
#include <iostream>
#include <string>
#include <fstream>
#include "Madlibs.h"
using namespace std;
int main ()
{
string filename, line;
ifstream inFile;
Madlibs story;
cout << "Enter the name of the file containing the paragraph --> ";
cin >> filename;
inFile.open(filename.c_str(), ios::in);
if (inFile.fail())
{
cerr << "\n** Unable to open input file - " << filename << " **\n\n";
}
else
{
while (!inFile.eof())
{
getline(inFile, line, '\n');
story.createStory(line);
}
story.display();
}
inFile.close();
return 0;
} // end of main
And here is my header file:
Code:
#ifndef MADLIBS_H
#define MADLIBS_H
#include <string>
class Madlibs
{
public:
//Constructor
Madlibs();
//Function to display
void display();
//Function to create the Story
string createStory(string s);
private:
string word;
string sentence;
};
#endif
And I think it should work, but I'm getting these errors:
Code:
--------------------Configuration: proj5 - Win32 Debug--------------------
Compiling...
proj5main.cpp
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(16) : error C2146: syntax error : missing ';' before identifier 'createStory'
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(16) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(16) : error C2061: syntax error : identifier 'string'
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(19) : error C2146: syntax error : missing ';' before identifier 'word'
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(19) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(19) : error C2501: 'word' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(20) : error C2146: syntax error : missing ';' before identifier 'sentence'
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(20) : error C2501: 'string' : missing storage-class or type specifiers
c:\program files\microsoft visual studio\myprojects\proj5\madlibs.h(20) : error C2501: 'sentence' : missing storage-class or type specifiers
C:\Program Files\Microsoft Visual Studio\MyProjects\proj5\proj5main.cpp(33) : error C2660: 'createStory' : function does not take 1 parameters
Error executing cl.exe.
proj5.exe - 10 error(s), 0 warning(s)
Please help!!