帮助理解我的错误。 [英] Help understanding my erros.

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

问题描述

我是C ++的新手,我正在尝试创建一个模拟兔子群的程序。到目前为止,我刚刚开始,并希望让我的程序接受用户输入启动程序,并根据用户输入创建一个链接列表来启动程序。



我收到以下错误。

I am new to C++ and I am trying to create a program that will simulate a colony of bunnies. So far I am just starting out and want to make my program take in user input to start the program and based on the user input to create a linked list to start the program.

I get the following errors.

main.cpp:12:10: error: ‘s’ was not declared in this scope
   cin >> s;
          ^
main.cpp:16:2: error: ‘BunnyList’ was not declared in this scope
  BunnyList * colony = new BunnyList;
  ^
main.cpp:16:14: error: ‘colony’ was not declared in this scope
  BunnyList * colony = new BunnyList;
              ^
main.cpp:16:27: error: ‘BunnyList’ does not name a type
  BunnyList * colony = new BunnyList;
                           ^





我尝试了什么:





What I have tried:

#include <iostream>
#include <string>
#include <ctime>
#include <string>

//#include "ListofBunny.h"

int main (){
	 
	 string s;
	 cout << "Please press 's' to start the pass";
	 cin >> s;
	 
	 while(s == 's' | s == 'S'){
		 //creates a linked list of bunnies 
	BunnyList * colony = new BunnyList;
	 }
	
}

推荐答案

正如其他人已经注意到的那样,你要么使用使用(原谅双关语)声明,例如

As others already noted, you shuold either use the using (pardon the pun) declaration, e.g.
#include <iostream>
#include <string>
#include <ctime>
using namespace std;
//..





或先于 std :: 说明符属于标准命名空间的对象,例如



or precede with the std:: specifier the object belonging to the 'standard' namespace, e.g.

int main()
{
  std::string s;
  //..





此外,如果你的程序使用 BunnyList类(或 struct )然后你需要包含声明这样的(或 struct )的头文件。



Moreover if your program uses the BunnyList class (or struct) then you need to include the header file declaring such a class (or struct).


对于名为BunnyList的类的使用,您必须声明或实现它。通常标题应该具有名称BunnyList.h并且具有以下内容:



For the use of a class named BunnyList you must declare or implement it. Normally the header should have the name "BunnyList.h" and have such content:

class BunnyList {
//todo
};



你的s应该是一个字母


Your s should be a char

char s = 0;//initial value
BunnyList * colony = new BunnyList();// good style with braces (if class) WITHOUT if struct



祝你好运。观看Youtube上的一些教程; - )


Good luck. Watch some tutorial on Youtube ;-)


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

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