错误:'s'未命名类型
Error: 's' does not name a type
这是
代码给我的错误,我不知道为什么。它说错误发生在倒数第二行,或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... nn";
cout << "tWarrior: nt Health:75nt Attack:25nn";
cout << "tWizard: nt Health:25nt Attack:75nn";
cout << "tRogue: nt Health:50nt Attack:50n";
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 << "nnMake 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);
}
当完全按照原样输入到 MSVC++ Express 2010(Win32 控制台应用,没有预编译标头)时,该代码可以完美运行。
因此,我怀疑您要么在其他地方遇到问题(项目中的其他代码,损坏的头文件,许多其他可能性),要么您没有发布导致问题的代码。
's' does not name a type
错误通常在需要类型名称的地方使用s
时显示。您显示的代码并非如此。
顺便说一下,如果您没有将Microsoft编译器用于Windows代码,则需要指定该编译器。可能是MinGW等人没有像Visual C++那样很好地整合。
相关文章:
- 未命名的非类型模板参数有什么意义?
- C++包含函数标头会给出错误'__dest'未命名类型
- 错误:"cast"未命名类型void setCastDescription(std::string
- C++ 错误:(类名)未命名类型
- C++ ,错误:命名空间'std'中的'shared_ptr'未命名模板类型
- src/caffe/parallel.cpp:70:1:错误:“参数”未命名类型
- 错误:'int_type'未命名类型 - 如何继承 typedefs 和用法
- 如何修复错误,迭代器未在此范围内声明,并且迭代器未命名类型'
- 使用 mex 编译库时出错 - __int 64 未命名类型
- 错误:"某个类"未命名类型。如何解决这个问题?
- 命名空间中的'bad_cast' 'std' 未命名类型错误
- QT:错误 ["*"令牌之前的预期")",并且主窗口未命名类型]
- 命名结构与未命名结构的类型别名
- "root"未命名类型错误
- Stack.h:13:3:错误:“单元格”未命名类型
- 错误:命名空间“PQXX”中的“行”未命名类型
- YYY 中的错误 XXX 未命名类型
- C 构建错误:类未命名类型
- 错误:"QGeo坐标"未命名类型
- 错误:"__NDK_FPABI__"未命名类型