错误:' s'没有命名类型

时间:2014-04-07 05:38:22

标签: c++

这是代码给我的错误,我无法弄清楚原因。它表示错误发生在倒数第二行或者introStory函数的结尾。 (我现在正在括号中写这个,因为据说我的帖子主要是代码,我需要添加更多细节。)

#include <iostream>
#include <string>
#include "windows.h"
using namespace std;

string classChooser();
string nameChooser();
void introStory(string position, string name);

int main()
{
    string charPosition = classChooser();
    cout << "You chose " << charPosition << " as your class.";
    string charName = nameChooser();
    introStory(charPosition,charName);

    return 0;
}

string classChooser()
{

    string position;
    while(true)
    {
        cout << "Choose a class wisely... \n\n";
        cout << "\tWarrior: \n\t  Health:75\n\t  Attack:25\n\n";
        cout << "\tWizard: \n\t  Health:25\n\t  Attack:75\n\n";
        cout << "\tRogue: \n\t  Health:50\n\t  Attack:50\n";

        cout << "\nWhich class do you want to select? : ";
        cin >> position;
        if(position == "wizard" ||position ==  "warrior" ||position ==  "rogue" ||position ==  "Wizard" ||position ==  "Warrior" ||position ==  "Rogue")
        {
            system("cls");
            return position;
        }
        else
        {
            cout << "\n\nMake sure you typed in the word correctly, and used appropriate capitalization.";
            Sleep(3200);
            system("cls");
            continue;
        }
    }
}

string nameChooser()
{
    string name;
    cout << "\nPlease choose a name for your hero: ";
    cin >> name;
    cout << "\nYour name is now " << name;
    return name;
}
void introStory(string position, string name)
{
    cout << "\nLet the story begin...";
    Sleep(2100);
    system("cls");
    cout << "Once upon a time in a poor village, a young kid named " << name << " was digging a hole.";
    Sleep(4000);
    cout << "After digging for a couple hours he came across a chest.";
    Sleep(3200);
    string weapon;
    if(position == "Warrior" || position == "warrior")
        weapon = "sword";
    else if(position == "Wizard" || position == "wizard")
        weapon = "wand";
    else
        weapon = "dagger";
    cout << "When he opened it, he found a " << weapon;
    Sleep(2000);
    cout << "That was exactly what he had been wanting for the past couple of months.";
    Sleep(3000);
    cout << "You see, " << name << " wanted to be a " << position;
    Sleep(2700);
    cout << "So a " << weapon << " was the perfect choice.";
    Sleep(2100);
    cout << "With his new " << weapon << " he could finally explore the dark cave his father was lossed in.";
    Sleep(4000);
    cout << "He could slay the monsters in there everyone was so terrified of.";
    Sleep(3200);
    cout << "He headed toward the cave.";
    Sleep(2000);
}

1 个答案:

答案 0 :(得分:0)

该代码在完全输入到MSVC ++ Express 2010(Win32控制台应用程序,没有预编译头文件)时,完美无缺。

因此,我怀疑你在其他地方遇到问题(项目中的其他代码,损坏的头文件,许多其他可能性),或者你没有发布导致问题的代码。

当您使用's' does not name a type时,通常会显示s错误,其中包含类型名称。你所展示的代码并非如此。


顺便说一句,如果您使用Microsoft的Windows代码编译器,则需要指定。可能是像MinGW等人那样没有像Visual C ++那样很好地集成。