小编tho*_*mas的帖子

如何在我的特定代码中实现动态bitset

我正在使用bitset并提高我的代码的性能我想将其更改为动态bitset,但在阅读了与此相关的一些帖子之后,我仍然不知道定义代码的方法.

所以我附上了我的代码,我想知道你们中是否有人可以帮助我给我一些关于我应该修改什么以及如何修改的想法.

提前致谢 :)

// Program that converts a number from decimal to binary and show the positions
// where the bit of the number in binary contains 1

#include <bitset>
#include <iostream>
#include <string>
#include <vector>

using namespace std;


int main()
{

    unsigned long long int dec;
    bitset<5000> binaryNumber;
    bitset<5000> mask;
    mask = 0x1;

    cout << "Write a number in decimal: ";
    cin >> dec;

    // Conversion from decimal to binary
    int x;
    for (x = 0; x < …
Run Code Online (Sandbox Code Playgroud)

c++ bitset

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

创建巨大矩阵时的问题

我试图用随机字符创建一种表并将其写入文件,但我有一个问题.当我想创建大表时出现问题.例如,对于具有10行x 5列的表,一切都很完美,但对于具有1.000.000行和100列的表,我有错误.你有什么想法我能解决这个问题吗?

我附上了我创建的代码:

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<ctime>
#include<sstream>

using namespace std;

int main()
{
    int rows, columns, rowsMax, columnsMax; 
    int element1;
    char word[10];

    cout<<"Write the number of rows of your table: ";
    cin>>rowsMax;

    cout<<"Write the number of columns of your table: ";
    cin>>columnsMax;

    string matriz[100000][5]; // Here I write the number of row and columns that must be the same than the numbers introduced as input

    string table ("Table1");

    ofstream myfile (table);
    if(myfile.is_open())
    srand(1);
    for(rows=0;rows<rowsMax;rows++)
    {
        for(columns=0;columns<columnsMax;columns++)
        {
            element1 …
Run Code Online (Sandbox Code Playgroud)

c++

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

标签 统计

c++ ×2

bitset ×1