矢量在cpp [英] Vector in cpp

查看:88
本文介绍了矢量在cpp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我想知道如何使用std :: vector变量。

我尝过这样的类,但是我收到错误,我不知道为什么......

错误

lib / image.h:13:错误:非成员使用声明在课堂范围内

lib / image.h:13:错误:预期?;?之前?<?令牌


代码

#ifndef IMAGE_H

#define IMAGE_H


#包括< stdio.h>


/ *为图像创建类* /

class Image {

public:

int w; //图像的宽度。

int h; //图像的高度。

int dim; //图像的维度。

//图像的数组RGB类型uchar。

std :: vector< unsigned char> arr;

};


#endif / * IMAGE_H * /

解决方案

< blockquote>

Marcelo写道:

你好,

我想知道如何使用std :: vector变量。
我尝过类似这样的课,但是我得到了一个错误,我不知道为什么......
错误
lib / image.h:13:错误:使用声明为非 - 班级范围内的成员
lib / image.h:13:错误:预期'';'''''''<'''令牌

代码
#ifndef IMAGE_H
#define IMAGE_H

#include< stdio.h>
#include< vector> //我也会将上面更改为cstdio或使用c ++

streams。
/ *为图像创建类* /
类图像{
public:
int w; //图像的宽度。
int h; //图像的高度。
int dim; //图像的维度。
//图像的RGB类型uchar。
std :: vector< unsigned char> arr;
};

#endif / * IMAGE_H * /




我想我需要这个,因为那时编译工作得很好。


#include< vector.h>


然而,哪里可以有更多关于矢量类型的文档?


非常感谢


MArcelo


周三,2005年12月14日18:25:40 +0100,Marcelo< ma ******** @ yahoo.com>

写道:

您好,

我想知道如何使用std :: vector变量。
我尝试了类似这样的课程,但是我收到错误而且我不知道知道为什么......
错误
lib / image.h:13:错误:在类范围内使用非成员的声明
lib / image.h:13:错误:预期?;?之前?<?令牌

代码
#ifndef IMAGE_H
#define IMAGE_H

#include< stdio.h>

/ *为图像创建类* /
类图像{
public:
int w; //图像的宽度。
int h; //图像的高度。
int dim; //图像的维度。
//图像的RGB类型uchar。
std :: vector< unsigned char> arr;
};

#endif / * IMAGE_H * /




你忘了#include< vector>。 />

另外,stdio.h不是C ++。你还在使用printf吗?考虑一下C ++为您提供的

替代方案。


Hello,

I would like to know how to use the std::vector variable.
I have tried a class something like this, but I get an error and I don''t know why...
the error
lib/image.h:13: error: using-declaration for non-member at class scope
lib/image.h:13: error: expected ?;? before ?<? token

the code
#ifndef IMAGE_H
#define IMAGE_H

#include <stdio.h>

/*Create the class for the images */
class Image {
public:
int w; // The width of the image.
int h; // The height of the image.
int dim; // The dimension of the the image.
//The array RGB type uchar of the image.
std::vector<unsigned char> arr;
};

#endif /* IMAGE_H */

解决方案


Marcelo wrote:

Hello,

I would like to know how to use the std::vector variable.
I have tried a class something like this, but I get an error and I don''t know why...
the error
lib/image.h:13: error: using-declaration for non-member at class scope
lib/image.h:13: error: expected '';'' before ''<'' token

the code
#ifndef IMAGE_H
#define IMAGE_H

#include <stdio.h> #include <vector> // I would also change above to cstdio or use c++
streams.
/*Create the class for the images */
class Image {
public:
int w; // The width of the image.
int h; // The height of the image.
int dim; // The dimension of the the image.
//The array RGB type uchar of the image.
std::vector<unsigned char> arr;
};

#endif /* IMAGE_H */




I suppose that i need this, because then the compilation works just fine.

#include <vector.h>

However, where can I have more documentation about vector type?

thanks a lot

MArcelo


On Wed, 14 Dec 2005 18:25:40 +0100, Marcelo <ma********@yahoo.com>
wrote:

Hello,

I would like to know how to use the std::vector variable.
I have tried a class something like this, but I get an error and I don''t know why...
the error
lib/image.h:13: error: using-declaration for non-member at class scope
lib/image.h:13: error: expected ?;? before ?<? token

the code
#ifndef IMAGE_H
#define IMAGE_H

#include <stdio.h>

/*Create the class for the images */
class Image {
public:
int w; // The width of the image.
int h; // The height of the image.
int dim; // The dimension of the the image.
//The array RGB type uchar of the image.
std::vector<unsigned char> arr;
};

#endif /* IMAGE_H */



You forgot #include <vector>.

Also, stdio.h isn''t very C++. Are you still using printf? Consider the
alternatives C++ offers you.


这篇关于矢量在cpp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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