String is not recognized?

This is a discussion on String is not recognized? within the C++ Programming forums, part of the General Programming Boards category; Here is my main function: Code: /* CSE 231 Project 5 Solution This file simulates the madlib game by reading ...

  1. #1
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    Posts
    65

    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!!

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    #ifndef MADLIBS_H
    #define MADLIBS_H
    
    #include <string>
    
    class Madlibs
    {
    public:
    	//Constructor
    	Madlibs();
    
    	//Function to display
    	void display();
    
    	//Function to create the Story
    	std::string createStory(std::string s);
    
    private:
    	std::string word;
    	std::string sentence;
    };
    
    #endif
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    Registered User Azmeos's Avatar
    Join Date
    Jun 2003
    Posts
    65
    thanks

  4. #4
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    or, you could use using namespace std;

    but in this case, Jawib's suggestion is much better.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  5. #5
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    or you could find a midground: put 'using std::string;' at the top...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21