错误C2059:语法错误:'namespace' [英] error C2059: syntax error : 'namespace'

查看:1382
本文介绍了错误C2059:语法错误:'namespace'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

// *************************************************************
// Project
// CSCE 3110, Summer 2012
// Student: Ka Son Chan KaSonChan@my.unt.edu
// Instructor: Erwin Guillermo Fernandex-Ordonez
// Date: August 3, 2012
//
// Parser.cpp
// Description: Parser.cpp contains definition
// from Parser.h classes and functions prototypes.
// *************************************************************
#include "stdafx.h"
#include "parser.h"
#include "HashTable.h"
#include "CountFrequency.h"

#include <iostream>
#include <string>
#include <cstring>
using namespace std;

// *************************************************************
// Definition of function prototypes
// *************************************************************
// Parser() function
// Parameters list: string line, int fileNo,
// class HashTable & HT, struct frequencyList FL[]
// Function call list: countFrequency() from CountFrequency.h
//                     removeCommaBehind(),
//                     removerPeriodBehind(),
//                     removePBehind(),
//                     removePBefore(),
//                     removeApsBehind(),
//                     removeApBehind(),
//                     removeIesBehind(),
//                     removeSLBefore(),
//                     removeEsBehind(),
//                     removeSBehind(),
//                     removeIngBehind(),
//                     removeEdBehind
// Parser() function calls the functions above to help parse
// the line from reading from the documents and also call
// countFrequency from CountFrequency.h to count the frequency
// that the word occur in the file.
void parser(string line, int fileNo, class HashTable & HT, frequencyList FL[])
{
        // Variables declarations
        char * cStr, * cPtr;
        string tempString;

        // Define cStr = the size of line + 1
        // Copy the string line to char * cStr
        cStr = new char [line.size() + 1];
        strcpy (cStr, line.c_str());

        // Parese cStr by " "
        cPtr = strtok (cStr, " ");
        while (cPtr != NULL)
        {
                if (strcmp(cPtr, "</TEXT>") != 0 && *cPtr != '.')
                {
                        tempString = string(cPtr);

                        // Call removeCommaBehind function to remove , behind word
                        removeCommaBehind(tempString);

                        // Call removePeriodBehind function to remove . behind word
                        removePeriodBehind(tempString);

                        // Call removePBehind function to remove ) behind word
                        removePBehind(tempString);

                        // Call removePBehind function to remove ( before word
                        removePBefore(tempString);

                        // Call removeAsBehind function to remove 's behind word
                        removeApsBehind(tempString);

                        // Call removeAsBehind function to remove ' behind word
                        removeApBehind(tempString);

                        // Call removeIesBehind function to remove suffix ies and replace suffix by y
                        removeIesBehind(tempString);

                        // Call removeSLBefore function to remove / before word
                        removeSLBefore(tempString);

                        // Call removeEsBehind function to remove suffix es
                        removeEsBehind(tempString);

                        // Call removeSBehind function to remove suffix s
                        removeSBehind(tempString);

                        // Call removeIesBehind function to remove suffix ing
                        removeIngBehind(tempString);

                        // Call removeEdBehind function to remove suffix ed
                        removeEdBehind(tempString);

                        // If the tempString != the following words or characters
                        if(tempString.compare("a") != 0)
                        if(tempString.compare("an") != 0)
                        if(tempString.compare("any") != 0)
                        if(tempString.compare("all") != 0)
                        if(tempString.compare("and") != 0)
                        if(tempString.compare("are") != 0)
                        if(tempString.compare("at") != 0)
                        if(tempString.compare("as") != 0)
                        if(tempString.compare("b") != 0)
                        if(tempString.compare("be") != 0)
                        if(tempString.compare("been") != 0)
                        if(tempString.compare("but") != 0)
                        if(tempString.compare("by") != 0)
                        if(tempString.compare("c") != 0)
                        if(tempString.compare("ca") != 0)
                        if(tempString.compare("can") != 0)
                        if(tempString.compare("d") != 0)
                        if(tempString.compare("e") != 0)
                        if(tempString.compare("f") != 0)
                        if(tempString.compare("for") != 0)
                        if(tempString.compare("from") != 0)
                        if(tempString.compare("g") != 0)
                        if(tempString.compare("ga") != 0)
                        if(tempString.compare("h") != 0)
                        if(tempString.compare("ha") != 0)
                        if(tempString.compare("had") != 0)
                        if(tempString.compare("have") != 0)
                        if(tempString.compare("he") != 0)
                        if(tempString.compare("i") != 0)
                        if(tempString.compare("in") != 0)
                        if(tempString.compare("is") != 0)
                        if(tempString.compare("it") != 0)
                        if(tempString.compare("j") != 0)
                        if(tempString.compare("k") != 0)
                        if(tempString.compare("l") != 0)
                        if(tempString.compare("like") != 0)
                        if(tempString.compare("m") != 0)
                        if(tempString.compare("me") != 0)
                        if(tempString.compare("my") != 0)
                        if(tempString.compare("n") != 0)
                        if(tempString.compare("near") != 0)
                        if(tempString.compare("no") != 0)
                        if(tempString.compare("not") != 0)
                        if(tempString.compare("o") != 0)
                        if(tempString.compare("of") != 0)
                        if(tempString.compare("on") != 0)
                        if(tempString.compare("or") != 0)
                        if(tempString.compare("out") != 0)
                        if(tempString.compare("over") != 0)
                        if(tempString.compare("p") != 0)
                        if(tempString.compare("q") != 0)
                        if(tempString.compare("r") != 0)
                        if(tempString.compare("s") != 0)
                        if(tempString.compare("she") != 0)
                        if(tempString.compare("so") != 0)
                        if(tempString.compare("t") != 0)
                        if(tempString.compare("that") != 0)
                        if(tempString.compare("th") != 0)
                        if(tempString.compare("the") != 0)
                        if(tempString.compare("them") != 0)
                        if(tempString.compare("their") != 0)
                        if(tempString.compare("they") != 0)
                        if(tempString.compare("this") != 0)
                        if(tempString.compare("to") != 0)
                        if(tempString.compare("u") != 0)
                        if(tempString.compare("up") != 0)
                        if(tempString.compare("us") != 0)
                        if(tempString.compare("v") != 0)
                        if(tempString.compare("w") != 0)
                        if(tempString.compare("wa") != 0)
                        if(tempString.compare("was") != 0)
                        if(tempString.compare("we") != 0)
                        if(tempString.compare("were") != 0)
                        if(tempString.compare("which") != 0)
                        if(tempString.compare("who") != 0)
                        if(tempString.compare("will") != 0)
                        if(tempString.compare("with") != 0)
                        if(tempString.compare("x") != 0)
                        if(tempString.compare("y") != 0)
                        if(tempString.compare("z") != 0)
                        if(tempString.compare("\0") != 0)
                        if(tempString.compare("\0\n") != 0)
                        if(tempString.compare(" ") != 0)
                        if(tempString.compare(" \n") != 0)
                        if(tempString.compare("\n") != 0)
                        if(tempString.compare(",") != 0)
                        if(tempString.compare(".") != 0)
                        if(tempString.compare("=") != 0)
                        {
                                // Call countFrequency() function
                                countFrequency(tempString, FL);
                        }
                }
                cPtr = strtok(NULL, "()/ ");
        }
        delete[] cStr;
}
// End of parser() function

// RemoveCommaBehind() function
// Parameters list: string & tempSTring
// RemoveCommaBehind() removes the comma "," behind from the
// parameter string tempString
void removeCommaBehind(string &tempString)
{
        if(tempString.find(",", tempString.length() - 2) < 35)
        {
                tempString.replace(tempString.find(",", tempString.length() - 2), tempString.length(), "\0");
        }
}
// End of removeCommaBehind() function

// RemovePeriodBehind() function
// Parameters list: string & tempSTring
// RemovePeriodBehind() removes the period "." behind from the
// parameter string tempString
void removePeriodBehind(string &tempString)
{
        if(tempString.find(".", tempString.length() - 2) < 35)
        {
                tempString.replace(tempString.find(".", tempString.length() - 2), tempString.length(), "\0");
        }
}
// End of removePeriodBehind() function

// RemoveSLBehind() function
// Parameters list: string & tempSTring
// RemoveSLBehind() removes the slash "/" behind from the
// parameter string tempString
void removeSLBefore(string &tempString)
{
        if(tempString[0] == '/')
                tempString.erase(0, 1);
}
// End of removeSLBefore() function

// RemoveIesBehind() function
// Parameters list: string & tempSTring
// RemoveIesBehind() removes the "ies" behind from the
// parameter string tempString and replace with "y"
void removeIesBehind(string &tempString)
{
        if(tempString.find("ies", tempString.length() - 3) < 35)
        {
                tempString.replace(tempString.find("ies", tempString.length() - 3), tempString.length(), "y\0");
        }
}
// End of removeIesBehind() function

// RemoveEsBehind() function
// Parameters list: string & tempSTring
// RemoveEsBehind() removes the "es" behind from the
// parameter string tempString
void removeEsBehind(string &tempString)
{
        if(tempString.find("sses", tempString.length() - 4) < 35)
        {
                tempString.replace(tempString.find("sses", tempString.length() - 4), tempString.length(), "ss\0");
        }
}
// End of removeEsBehind() function

// RemoveSBehind() function
// Parameters list: string & tempSTring
// RemoveSBehind() removes the "s" behind from the
// parameter string tempString
void removeSBehind(string &tempString)
{
        if(tempString.find("s", tempString.length() - 1) < 35)
        {
                tempString.replace(tempString.find("s", tempString.length() - 1), tempString.length(), "\0");
        }
}
// End of removeSBehind() function

// RemoveIngBehind() function
// Parameters list: string & tempSTring
// RemoveIngBehind() removes the "ing" behind from the
// parameter string tempString
void removeIngBehind(string &tempString)
{
        if(tempString.find("ing", tempString.length() - 3) < 35)
        {
                tempString.replace(tempString.find("ing", tempString.length() - 3), tempString.length(), "\0");
        }
}
// End of removeIngBehind() function

// RemoveEdBehind() function
// Parameters list: string & tempSTring
// RemoveEdBehind() removes the "ed" behind from the
// parameter string tempString
void removeEdBehind(string &tempString)
{
        if(tempString.find("ed", tempString.length() - 2) < 35)
        {
                tempString.replace(tempString.find("ed", tempString.length() - 2), tempString.length(), "\0");
        }
}
// End of removeEdBehind() function

// RemoveApsBehind() function
// Parameters list: string & tempSTring
// RemoveApsBehind() removes the "'s" behind from the
// parameter string tempString
void removeApsBehind(string &tempString)
{
        if(tempString.find("'s", tempString.length() - 2) < 35)
        {
                tempString.replace(tempString.find("'s", tempString.length() - 2), tempString.length(), "\0");
        }
}
// End of removeApsBehind() function

// RemoveApBehind() function
// Parameters list: string & tempSTring
// RemoveApBehind() removes the "'" behind from the
// parameter string tempString
void removeApBehind(string &tempString);
void removeApBehind(string &tempString)
{
        if(tempString.find("'", tempString.length() - 2) < 35)
        {
                tempString.replace(tempString.find("'", tempString.length() - 2), tempString.length(), "\0");
        }
}
// End of removeApBehind() function

// RemovePBBefore() function
// Parameters list: string & tempSTring
// RemovePBBefore() removes the "(" at the beginning of the
// parameter string tempString
void removePBefore(string &tempString)
{
        if(tempString[0] == '(')
                tempString.erase(0, 1);
}
// End of removePBBefore() function

// RemovePBBehind() function
// Parameters list: string & tempSTring
// RemovePBBehind() removes the ")" behind from the
// parameter string tempString
void removePBehind(string &tempString)
{
        if(tempString.find(")", tempString.length() - 2) < 35)
        {
                tempString.replace(tempString.find(")", tempString.length() - 2), tempString.length(), "\0");
        }
}
// End of removePBBehind() function
// *************************************************************
// End of definition of function prototypes
// *************************************************************

推荐答案

The code you posted uses the term namespace only once, and correctly. The immediately preceding include is a system header and as such is extremely unlikely to cause a misinterpretation of that statement. This is not the source of the error.



The error message should refer to a line and file where the error occurred. Check that line, and the immediately preceding line(s) or maybe include statement. If you don’t spot the error yourself, come back and post only that code.
The code you posted uses the term namespace only once, and correctly. The immediately preceding include is a system header and as such is extremely unlikely to cause a misinterpretation of that statement. This is not the source of the error.

The error message should refer to a line and file where the error occurred. Check that line, and the immediately preceding line(s) or maybe include statement. If you don't spot the error yourself, come back and post only that code.


这篇关于错误C2059:语法错误:'namespace'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆