2014-04-07 95 views
0

这是代码给我的错误,我想不通为什么。它说错误发生在倒数第二行或introStory函数的结尾处。 (我因为是说我的文章主要是代码括号现在写这个,我需要增加更多的细节。)错误:“S”没有指定类型

#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); 
} 
+0

后更少的代码抄录错误。 – user93353

+3

[不可重现](http://rextester.com/WRA39241)。 –

+0

我不知道代码会导致错误。 @ user93353 – taborgreat

回答

0

该代码,进入正是时,由于是进入2010年MSVC++速成的(Win32控制台应用程序,没有预编译头文件),完美地工作。

因此,我怀疑你要么有其他地方的问题(在项目中的其他代码,损坏的头文件,其他的可能性主机),或者你还没有公布是造成该问题的代码。

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


顺便说一句,如果您使用Microsoft的用于Windows代码编译器是,你需要指定。 MinGW等人可能并不像Visual C++那么好集成。