当这运行:
if (Title != "") {
Server.s.Log("title found: " + Title);
if (TitleColor != "") {
NameTitle = "[" + TitleColor + Title + NameColor + "]";
} else {
NameTitle = "[" + Title + "]";
}
} else {
NameTitle = "";
}
Run Code Online (Sandbox Code Playgroud)
它认为标题有价值,事实上,标题绝对只是"",请帮助我吗?
串水果[200];
如何将字符串输入数组?
Example:
My mom has apples;
So , fruits array will contain:
fruits[0] = "My";
fruits[1] = "mom";
..........etc.
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
在构造和销毁期间调用虚方法会导致编译器错误?我听说做这件事很危险.
我知道,如果我有一个Class Base定义虚方法foo(),那么分辨率在所有子类中foo()都是动态的Base.因此,如果子类Derived重写foo()则Derived::foo()调用.那么为什么在构造/销毁期间调用虚方法会让编译器感到困惑?
从构造函数和它之外调用它们有什么区别?
我在互联网上搜索了很多,并且找到了简单的例子来打印矢量数据.
我尝试将它打印成阵列,虽然它没有用...
这是我试过的:
using namespace std ;
.....
const int MAX = 255 ;
vector <string> testersName[MAX];
cout << testersName[i] << endl;
Run Code Online (Sandbox Code Playgroud)
错误只在cout行中,第一行得到遵守,一切顺利..
我在testersName中获取了数据,但我收到此错误:
"错误1错误C2679:二进制'<<':没有找到哪个运算符采用'std :: vector <_Ty>'类型的右手操作数(或者没有可接受的转换)"
这是在一次采访中向我提出的问题.
如果Vtable是在编译时创建的,并且vptr在运行时被分配给对象,那么如果我们的类中有虚拟构造函数,那么为什么编译器会给出编译时错误?
我解释了整个机制.但是他对' 为什么编译时错误而不是运行时错误 ' 更感兴趣
我告诉他,C++指南是用来编写的,因此编译器会在编译时发送错误.
能否请你告诉我同样的原因
我试图在如何编程中编写练习2.19的程序,但我遇到了一些困难.
该方案应该让用户输入三个整数,然后显示sum,average和product那些整数.
我唯一的问题是显示最大和最小.当我运行程序并输入三个整数时(8, 9, and 10),输出读取Smallest is 8 AND Smallest is 9.
我希望你能告诉我为什么.
#include <iostream>
using namespace std;
int main ()
{ int x, y, z, sum, ave, prod;
cout << "Input three different integers ";
cin >> x >> y >> z;
sum = x + y + z;
cout << "\nThe sum is " << sum;
ave = (x + y + z) / 3;
cout << "\nThe …Run Code Online (Sandbox Code Playgroud) 我可以用C++做到这一点吗?
if (4<5<6)
cout<<"valid"<<endl;
Run Code Online (Sandbox Code Playgroud)
即双重比较?因为我知道我可以
bool a;
a = 1+2<3+4<5>6;//etc
Run Code Online (Sandbox Code Playgroud) 我一直在编写我的代码并声明并定义了所有必要的变量并包含了必要的头文件.它仍然在类构造函数中使用的任何函数上给出了"未解析的外部符号".
BowlingAlley.obj : error LNK2001: unresolved external symbol "private: void __thiscall BowlingAlley::addToMasterArray(int * const,int * const)" (?addToMasterArray@BowlingAlley@@AAEXQAH0@Z)
1>BowlingAlley.obj : error LNK2001: unresolved external symbol "private: void __thiscall BowlingAlley::createLaneArrays(void)" (?createLaneArrays@BowlingAlley@@AAEXXZ)
1>BowlingAlley.obj : error LNK2001: unresolved external symbol "int * laneVertices" (?laneVertices@@3PAHA)
Run Code Online (Sandbox Code Playgroud)
我的头文件如下.
#pragma once
#include <stdio.h>
#include <iostream>
#include <array>
class BowlingAlley
{
private:
void createLaneArrays();
void concatenateArrays(int array1[], int array2[], int containerArray[]);
int getNewArrayLength(int array1[], int array2[]);
//mutates an array creating the master draw array by using the two functions …Run Code Online (Sandbox Code Playgroud) 我希望结果是未定义的或其他东西,但输出是"10",为什么?
我想在调用函数后会破坏内存.
#include <iostream>
void f(int *p)
{
int l = 20;
int *k = &l;
p = k;
}
int main()
{
int i = 10;
int *j = &i;
f(j);
std::cout << *j;
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在为http客户端编写一个C++库.我对编程没有太多经验,所以请帮助我.
我有方法命名add.它有两个参数.第一个是类型名称,第二个是参数q.它是0到1 <0,1>之间的数字.点后应该有0到4位数.
我可以写它,但我不知道什么是更好的:
void add(std::string type, double q) - >我必须将q转换为此方法体中的std :: string.
void add(std::string type, std::string q) - >没关系,它更快但用户可能不太直观,因为它是一个数字(?)....
这是一个好主意,有两种方法:1)和2)?
请帮我.我没有经验......我知道这两种方法有效,但更好,更受欢迎.你怎么看?你会怎么写这个?
所以我创建了一个struct,其唯一元素是指向数组的指针.当我初始化这个数组时,我得到一个分段错误.你能告诉我为什么吗?
这是代码:
typedef struct {
int *data;
} A;
/* Class definition */
class C {
A* a;
public:
C(void);
};
/* Constructor */
C::C(void) {
a->data = new int[10];
}
int main(void) {
C();
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我在编译时遇到这两个错误,但我不明白我做的不对.
main.cpp | 107 |错误:在此范围中未声明'sqrt'
main.cpp | 107 |错误:在此范围中未声明'pow'
#include <iostream>
#include <Windows.h>
using namespace std;
struct Player
{
int x, y;
Player()
{
x = -1;
y = -1;
}
};
struct Ghost
{
int x, y, direction;
Ghost()
{
x = -1;
y = -1;
direction = 1;
}
};
const char SYMBOL_EMPTY = ' ';
const char SYMBOL_PLAYER = '@';
const char SYMBOL_GHOST = 'G';
const char SYMBOL_WALL = '#';
const int MapDx = 10;
const int …Run Code Online (Sandbox Code Playgroud) 我有一个特殊的要求,但无法找到解决方案.
class Base
{
public:
void func()
{
//access the member say 'var' of derived class
}
}
Run Code Online (Sandbox Code Playgroud)
c++ ×12
class ×2
inheritance ×2
string ×2
arrays ×1
base-class ×1
boolean ×1
c# ×1
comparison ×1
constructor ×1
declaration ×1
input ×1
math ×1
oop ×1
operators ×1
output ×1
parameters ×1
pearson ×1
pointers ×1
scope ×1
structure ×1
visual-c++ ×1
vtable ×1