小编pen*_*enu的帖子

如何用长度初始化std :: string?

如果在编译时确定字符串的长度,我该如何正确初始化它?

#include <string>
int length = 3;
string word[length]; //invalid syntax, but doing `string word = "   "` will work
word[0] = 'a'; 
word[1] = 'b';
word[2] = 'c';
Run Code Online (Sandbox Code Playgroud)

...所以我可以做这样的事情?

示例:http://ideone.com/FlniGm

我这样做的目的是因为我有一个循环将字符从另一个字符串的某些区域复制到一个新字符串.

c++ string

8
推荐指数
4
解决办法
2万
查看次数

从父类访问子变量?

我该怎么做呢?

class test
{
    public static function run() {
        echo "Number is: ".$num;
    }
} 

class testchild extends test
{
    protected static $num = 5;
    public static function exec()  {
        $num = 5;
        parent::run();
    }
}
Run Code Online (Sandbox Code Playgroud)

testchild::exec(); 说未定义的变量“num”。

http://ideone.com/WM7tHk

我如何访问这个变量?

php class

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

这堂课怎么了?

我认为问题是在main()中,但这编译得很好,但我得不到输出.我想也许它不是正确的,因为在调试模式下它说
" myCharQ {item=0x0018fa00 "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ̺yâpú" front=-858993460 rear=-858993460 ...}"

你会如何改写它以使它合适?我刚开始上课,所以任何帮助都会有用.

以下是基于Array的Queue类

#include <iostream>
#include <cstdlib>
using namespace std;

const int MaxQueueSize = 10; // Queue Struct can hold up to 10 char.
typedef char ItemType; // the queue's data type is char

class CPPQueue
{
public:
    CPPQueue();
    ItemType item[MaxQueueSize];
    void initQueue(CPPQueue q);
    bool IsEmpty(CPPQueue q);
    bool IsFull(CPPQueue q);
    void Enqueue(CPPQueue q, ItemType newItem);
    void PrintQ(const CPPQueue q);
    void PrintQueueInfo(CPPQueue myQ);
    ItemType Dequeue(CPPQueue q);
private:
    int front, rear;
    int count;
}; …
Run Code Online (Sandbox Code Playgroud)

c++ class

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

我无法迭代 javascript 数组

我在这里疯了,我有一个如下所示的关联数组,它是在页面加载完成后定义的。然而Array.forEach又回来了undefined,我不知道为什么。该数组肯定是在循环期间填充的。谁能给我任何想法吗?也不适用于 JQuery$.each

在此输入图像描述

javascript

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

C++ - 连接字符串(如PHP?)

我环顾四周,但没有找到一个好的答案.

我有这样的文件: text1.txt text2.txt text3.txt

用户想要指定要打开的文件:

int x;
string filename;
cout << "What data file do you want to open? (enter an int between 1 -> 3): ";
cin >> x;
filename = "P3Data" << x << ".txt" ; //does not compile

myfile.open(filename);
Run Code Online (Sandbox Code Playgroud)

这样做的正确方法是什么?

c++ string

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

Big O 和 Big Omega 是一样的,但相反?

这是真的?

f(n) = O(g(n))  === g(n) = Omega(f(n))
Run Code Online (Sandbox Code Playgroud)

基本上它们可以互换,因为它们是对立的吗?

那么如果 F 在 G 的 Big O 中,那么 G 是 F 的 Big Omega?

big-o big-theta

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

标签 统计

c++ ×3

class ×2

string ×2

big-o ×1

big-theta ×1

javascript ×1

php ×1