相关疑难解决方法(0)

什么是阵列衰减?

什么是阵列的衰变?与数组指针有关系吗?

c c++ arrays pointers

358
推荐指数
8
解决办法
5万
查看次数

std :: array vs array performance

如果我想构建一个非常简单的数组

int myArray[3] = {1,2,3};
Run Code Online (Sandbox Code Playgroud)

我应该用std::array吗?

std::array<int, 3> a = {{1, 2, 3}};
Run Code Online (Sandbox Code Playgroud)

使用std :: array比使用常规的有什么好处?性能更高吗?更容易处理复制/访问?

c++ c++11 stdarray

53
推荐指数
6
解决办法
3万
查看次数

C++中的数组内容相等

有没有办法让相等运算符用于比较相同类型的数组?

例如:

int x[4] = {1,2,3,4};
int y[4] = {1,2,3,4};
int z[4] = {1,2,3,5};
if (x == y) cout << "It worked!"
Run Code Online (Sandbox Code Playgroud)

我知道原样,它只是比较指针值 - 但我希望有某种typedef技巧或类似的东西,所以它不需要循环或memcmp调用.

c++

4
推荐指数
3
解决办法
3754
查看次数

使用==比较字符串

可以编写如下所示的代码.

问题:即使我输入正确的员工ID,它也总是说"无效的员工ID".
请告诉我为什么以及如何正确地做到这一点.

#include <iostream>
#include <iomanip>
using namespace std;
char select, js;
char empid[4];
double bSalary, bonus, tot=0.0;
int main()
{
    do
    {
        cout<<"Employee id: ";
        cin>>empid;
        if(empid=="M001" || empid=="A004" || empid == "M002") //these are employee ids
        {   
            cout<<"Job Status: ";
            cin>>js;
            if(js=='P' || js=='C')
            {
                cout<<"Basic Salary: ";
                cin>>bSalary;
                if(bSalary>75000 && js=='P')
                {
                    bonus = bSalary*(20.0/100.0);
                    tot = tot + bonus + bSalary;
                }
                else if(bSalary>75000 && js=='C')
                {
                    bonus = bSalary*(15.0/100.0);
                    tot = tot + …
Run Code Online (Sandbox Code Playgroud)

c++ string if-statement

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

' &lt;' 运算符的比较行为

为什么打印“Popescu”而不是“Ionescu”,因为“Popescu”>“Ionescu”?

#include <iostream>

using namespace std;

int main(){

    char v[3][100] = {"Popescu","Ionescu","Vasilescu"};
    if(v[0]<v[1]){
        cout << v[0];
    }else{
        cout << v[1];
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ string

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

两个数组是否等于函数c ++

我正在尝试执行与数组比较的函数,如果它们相同则返回true.现在数组很简单,稍后会推进但我仍然坚持使用该testEqual功能.所以这是代码

int n = 5;
int array[5] = {5,10,3,4,7};
bubbleSort(pole,n);

int array2[5] = {3,4,5,7,10};
testEqual( array , array2 , "bubbleSort");
Run Code Online (Sandbox Code Playgroud)

这是testEqual我需要在阵列上重制的功能,但我不知道如何.

bool testEqual(int i1, int i2, const string testName) {
    bool myresult = (i1 == i2);
    return myresult;
}
Run Code Online (Sandbox Code Playgroud)

像bubbleSort这样的其他功能很好,我只需要重新制作testEqual.

c++ arrays compare function

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

标签 统计

c++ ×6

arrays ×2

string ×2

c ×1

c++11 ×1

compare ×1

function ×1

if-statement ×1

pointers ×1

stdarray ×1