2014-04-07 98 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++那麼好集成。