小编Ben*_*ley的帖子

一天增加一定时间?

我希望增加使用一天中的特定时间(MFC类)CTimeCTimeSpan.我的目标是使用CTimeSpan将time1()中给出的时间增加一天CTime time1.

我如何链接

CTime time1(2012, 4, 1, 1, 0, 0);
Run Code Online (Sandbox Code Playgroud)

CTimeSpan span1(1, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

所以CTimeSpan::CTimeSpan使用time1给出的日期将日数增加1?

c++ mfc

1
推荐指数
1
解决办法
654
查看次数

srand(),C++的问题

我正在尝试编写一个使用种子生成伪随机数的程序.但是,我遇到了问题.

我收到这个错误

39 C:\Dev-Cpp\srand_prg.cpp void value not ignored as it ought to be 
Run Code Online (Sandbox Code Playgroud)

使用此代码

#include <iostream>
#include <iomanip>
#include <sstream> 
#include <limits>
#include <stdio.h>

using namespace std ;

int main(){
    int rand_int;
    string close ;

    close == "y" ;

    cout << endl << endl ;
    cout << "\t ___________________________________" << endl ;
    cout << "\t|                                   |" << endl ;
    cout << "\t|   Pseudorandom Number Game!       |" << endl ;
    cout << "\t|___________________________________|" << endl ;
    cout << endl << endl …
Run Code Online (Sandbox Code Playgroud)

c++ srand

0
推荐指数
1
解决办法
3395
查看次数

在结构中包含std :: map?好吗?

class X_class{
public:

struct extra
{int extra1;
 int extra2;
 int extra3;
};
enum a
{
 n,m};

struct x_struct{
char b;
char c;
int d;
int e;
std::map <int, extra> myExtraMap;

};
};
Run Code Online (Sandbox Code Playgroud)

在我的代码中我定义:

x_struct myStruct;

为什么我编译错误编译上面的类?错误要么说:1)预期; 在<on the line ---我在哪里定义了map(上图)我是否消除了std ::或2)错误:无效使用::; 错误:预期; 在<令牌之前

c++ stl map

0
推荐指数
1
解决办法
315
查看次数

检查C++中是否存在bmp文件

我创建一个文件,一个bmp文件,并将其存储在某个目录中.我想要检查的是它在那之后(所以创作是否成功).我有

FILE *pfile;
pfile = fopen("C:\Users\me\Test-Outputs\Capture Output\test.bmp", "r");

if(pfile != NULL)
    worked!
else 
    didnt work!!
Run Code Online (Sandbox Code Playgroud)

但它不起作用.它说该文件即使存在也不存在.谁知道我哪里出错了?

c c++ windows

0
推荐指数
1
解决办法
320
查看次数

矢量值分配

我有这段代码:

    while(fileStream>>help)
    {
        MyVector.push_back(help);
    }
Run Code Online (Sandbox Code Playgroud)

...并且可以说文件"fileStream"中有1个句子:今天是晴天.现在当我这样做:

    for(int i=0;i<MyVector.size();i++)
    {
         printf("%s\n", MyVector[i]);
    }
Run Code Online (Sandbox Code Playgroud)

,重生是"日日活动日".而且,当然,它应该是那样的.变量声明如下:

    char *help;
    vector<char*> MyVector;
Run Code Online (Sandbox Code Playgroud)

编辑:我理解答案,谢谢...但是有没有办法存储文件中的文字vector<char*> MyVector(就像我想要的那样).这对我的其他计划来说会很棒.

c++ file vector

0
推荐指数
1
解决办法
489
查看次数

如何在类中初始化 char 数组?

我正要在类中初始化一个 char 数组:

class a{
    char a[25];
};

a::a(){
    a[] = {'a','b','c'};
}
Run Code Online (Sandbox Code Playgroud)

但给出编译时错误。

c++

0
推荐指数
1
解决办法
6009
查看次数

函数返回类型是c ++中的向量

我希望vector在我的代码中作为返回类型的函数,比如

class SocketTransportClient{
    void sendData(RMLInfoset *info){
        vector<unsigned long>::iterator blockIterator;
        vector<unsigned long> vectBlock=info->getRML(); // error :  error C2440: 'initializing' : cannot convert from 'std::vector<_Ty>' to 'std::vector<_Ty>'
    }
}

class RMLInfoset  {
    vector<unsigned int> RMLInfoset::getRML(){
        return  vectDataBlock;
    }
}
Run Code Online (Sandbox Code Playgroud)

但它显示错误'无法从'std :: vector <_Ty>'转换为'std :: vector <_Ty>''所以请任何人帮助我,谢谢.

c++ function vector

-1
推荐指数
2
解决办法
2万
查看次数

"int*a = new int"和"int*a = new int [5]"之间有什么区别?

我知道"int*a = new int"用于分配内存以包含int类型的单个元素."int*a = new int [5]"用于分配int类型的元素的块(数组).但是当我运行此代码时

int *a=new int;
for(int i=0;i<4;i++)
   a[i]=i;
for(int i=0;i<4;i++)
   cout<<a[i]<<endl;
Run Code Online (Sandbox Code Playgroud)

它运行没有任何错误,并显示正确的输出,所以什么时候应该使用"int*a = new int [5]"?或者它们在使用方面是否相同?我在codeblocks中使用gnu c ++编译器.

c++

-2
推荐指数
1
解决办法
662
查看次数

这两个项目中哪一个更好,为什么?

代码1

int A, B, MAX;
cout << "Give two numbers:" << endl;
cin >> A >> B;

if (A > B)
{ 
  MAX = A;
}
else 
{
  MAX = B;
}
cout << "Largest amongst given numbers is: ";
cout << MAX << endl;
return 0;
Run Code Online (Sandbox Code Playgroud)

代码2

int A, B, MAX;
cout << "Give two numbers:" << endl;
cin >> A >> B;

MAX = A;
if (B > MAX)
{
  MAX = B;
}
cout << "Largest amongst …
Run Code Online (Sandbox Code Playgroud)

c++

-4
推荐指数
1
解决办法
103
查看次数

标签 统计

c++ ×9

vector ×2

c ×1

file ×1

function ×1

map ×1

mfc ×1

srand ×1

stl ×1

windows ×1