小编Swo*_*ish的帖子

格式化 C++ 输出中的空格

我已经研究了几种解决方案来解决我的问题,但似乎没有什么对我有用。我希望我的输出能够对齐此代码上的所有姓名、所选号码和中奖金额。目前它输出:

3454 Atkins, Joe  7  6  5  4  3  2  1         7         $20.00    
4321 Barber, John      11  22  7  8  45  12  10         1         $0.00    
8976 Dollar, Kim      44  33  22  11  10  9  4         1         $0.00
Run Code Online (Sandbox Code Playgroud)

我相信我需要将名称右对齐才能解决此问题,但我尝试过的任何方法都不起作用。这是我的代码:

 cout << student_info[i].id_num;
 cout << setw(10) << student_info[i].student_name << setw(10);

 for(int j = 0; j < LOTTERYNUMBERS; j++)
     cout << student_info[i].lotteryNumbers[j] << "  ";

 cout << setw(10) << student_info[i].lotteryMatches << setw(10) << setprecision(2)
      << fixed << showpoint << "$" << student_info[i].prizeMoney << …
Run Code Online (Sandbox Code Playgroud)

c++

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

如何使用scanf()获取int

void pedir_diag(int* diag){
  scanf("%i", &diag);
}

int main() {
  int number;

  pedir_diag(&number);

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

当我编译引入一个整数并期望main中的数字int变量具有引入的值但未设置

我有这个,在我的代码中但我无法使用scanf()函数设置diag变量.

c

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

cpp运算符重载操作数位置[] vs ==

与有何char& operator[]不同bool operator==?一种将操作数放在中间[],另一种将操作数放在后面==。它如何知道将操作数放在哪里?左括号和右括号有什么特殊的技巧吗?

c++ operator-overloading

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

如何将structure/union数组的成员传递给函数

例如,我想显示结构/联合数组的一个成员的值,所以我想将它作为参数传递给一个只显示一个成员的函数,并且还将显示我作为参数传递的任何其他单个成员.

#include <iostream>
using namespace std;

union ThreeTypes
{
    char letter;
    int whole;
    double real;
};

void showArr(ThreeTypes[], int); // ?? What parameters to pass?

int main()
{
    const int SIZE = 50;
    ThreeTypes arr[SIZE];
    for (int i = 0; i < SIZE; i++)
        arr[i].real = 2.37;

    showArr(arr, SIZE, ??? ); // what argument to pass to display member?

    return 0;
}
void showArr(ThreeTypes arr[],int size,???) // also, what parameters??
{
    for (int i = 0; i < size; i++) …
Run Code Online (Sandbox Code Playgroud)

c++ c++17

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

关掉|| 运营商优化

有没有在VS C++ 2017年的任何选项,这样,当它建立了下面的程序都f()g()被称为?

#include <iostream>
using namespace std;
bool f()
{
    cout << "f" "\n";
    return true;
}
bool g()
{
    cout << "g" "\n";
    return false;
}
int main()
{

    if (f() || g())
        cout << "hello";
    cin.ignore(1);
}
Run Code Online (Sandbox Code Playgroud)

c++ short-circuiting

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

解析qt中的ini文件

我正在使用自定义的INI解析器,其参数是表单名称,父窗口小部件.语法如下所示:

int width = w->findchild("form_name","section_to_be_accessed_name").toInt();
Run Code Online (Sandbox Code Playgroud)

我的语法可能有点不对,因为我现在没有代码.我想添加INI文件第2页中提到的一些标签.这些图像的属性在ini文件本身中提到.即使是绝对的道路等.

我尝试了多种组合,但它不起作用.任何人都可以给我一个相同的语法吗?这里的回报值应该是多少?一个标签,我已经在Qt设计器中创建了标签.让我们说吧label1.但是有很多标签.请告诉我.

ini qt parsing label

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

I want to make a code that separates the values of individual digits in a number in c++. Ex: 12345 = 1+2+3+4+5

I cannot find why it isn't working. It outputs the number I inputted but with 1 digit less. Ex: 12345 ---> 1234.

I have already tried changing the while loop for a for one adding ifs and removing the parentheses.

#include <iostream>

using namespace std;

int num0, num1, x, y, z, num2;

int main()
{   
    cout << "input your number \n";
    cin >> num0;
    y = 0;
    x = 1;
    z = -1;
    num2 = 0;

    while (num0 > y) …
Run Code Online (Sandbox Code Playgroud)

c++

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

C ++ 17是基于C17的吗?

我注意到C ++ 17中的许多新功能来自C17。两种标准之间有关系吗?C函数和它们的C ++等效项之间是否有实际区别?

c c++ language-lawyer c++17 c17

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

C++如何使std :: function <bool()>返回一个布尔值

我有以下小代码示例:

std::function<bool()> isSet;

bool check() {
   bool tmp;
   return tmp;
}

std::function<bool()> isSet {
    return check();
}
Run Code Online (Sandbox Code Playgroud)

这给了我以下错误消息

could not convert 'isSet()' from 'bool' to 'std::function<bool()>'
Run Code Online (Sandbox Code Playgroud)

任何人都可以解释为什么以及如何解决它?

c++

-3
推荐指数
1
解决办法
202
查看次数