小编jam*_*ick的帖子

C++程序仅在打印数字时有效

我正在编写一个程序,可以计算出高于无符号long long的2的幂.基本上,我希望程序运行,然后在最后显示数字,但程序只有在我每次将它乘以2后显示数字时才有效.以下是工作方式的代码:

#include <iostream>
#include <stdio.h>
#include <climits>

using namespace std;

class big {
public:
    short container[SHRT_MAX];
    void print() {
        digits();
        for (; length != 0; length --) {
            cout << container[length - 1];
        }
        cout << "\n";
    }
    unsigned int digits() {
        if (!length) {
            for (length = 0; ; length++) {
                if (container[length] == '\0' &&container[length + 1] == '\0' && container[length + 2] == '\0' && container[length + 3] == '\0' && container[length + 4] == '\0') …
Run Code Online (Sandbox Code Playgroud)

c++

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

使用string时,__ toString()不得抛出异常错误

我正在使用Laravel 4进行我正在进行的项目.我需要从帖子中检索第一条评论.我使用以下代码来执行此操作.

$comments = Comment::where('post_id', $post->id)->first();
Run Code Online (Sandbox Code Playgroud)

这成功检索了第一条评论(我知道因为I print_r-ed $comments而且它返回了所有正确的信息).

但是,以下代码行会触发错误 __toString() must not throw an exception

<td>{{$comments->content}}</td>
Run Code Online (Sandbox Code Playgroud)

当我 - print_r它返回类型字符串,并返回正确的字符串.那为什么它甚至会$comments->content在它已经是字符串时尝试转换为字符串类型?

php laravel

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

Swift相当于(__bridge NSArray*)

我试图使用swift获取具有特定名称的联系人列表.我有以下代码:

let owner = owners[indexPath.row];

var addressBook = ABAddressBookCreateWithOptions(nil, nil)
var addressBookRef: ABAddressBookRef = Unmanaged<NSObject>.fromOpaque(addressBook.toOpaque()).takeUnretainedValue()

let ownerName: NSString = owner["name"]! as NSString

let allContacts = ABAddressBookCopyPeopleWithName(addressBookRef, ownerName)

println("All Contacts: \(allContacts)")
Run Code Online (Sandbox Code Playgroud)

显然,allContacts有一个值Swift.Unmanaged.我希望allContacts是一个NSArray.

在我正在关注的教程中allContacts,NSArray通过添加(__bridge NSArray*)来桥接ABAddressBookCopyPeopleWithName(addressBookRef, ownerName).

可能导致问题的原因是什么?

objective-c ios ios7 swift

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

viewWithTag为UITableViewCell返回nil

我有一个UITableView带有UITableViewCell标识符的原型contact.在界面构建器中,我正确构建了单元格,并将所有元素设置为正确的标记.当我尝试UILabel在使用标签101的单元格中编辑a 时cell.viewWithTag,该方法返回nil.这似乎只是iOS 8上的一个问题.我使用的是故事板和Swift.这是代码tableView:cellForRowAtIndexPath:

let contact = contacts[indexPath.row]
println("Contact: \(contact)")
cell = tableView.dequeueReusableCellWithIdentifier("contact") as UITableViewCell
(cell.contentView.viewWithTag(101) as UILabel).text = contact["name"]! as String
Run Code Online (Sandbox Code Playgroud)

uitableview viewwithtag swift ios8

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

C++编译器找不到#include <thread>

这是我的源文件的顶部:

#include <iostream>
#include <thread>
#include <fstream>
Run Code Online (Sandbox Code Playgroud)

...

thread help(startHelp);
Run Code Online (Sandbox Code Playgroud)

其中线程在函数handleRequestsFromServer和startHelp中是一个void函数.

g++在Mac OS X 10.8.4上编译时,我收到此错误:

$ g++ diskutilityhelper.cpp -o run.out
diskutilityhelper.cpp:5:18: error: thread: No such file or directory
diskutilityhelper.cpp: In function ‘void handleRequestsFromServer()’:
diskutilityhelper.cpp:140: error: ‘thread’ was not declared in this scope
diskutilityhelper.cpp:140: error: expected `;' before ‘bomb’
Run Code Online (Sandbox Code Playgroud)

我根本不明白这个错误.有人可以帮忙吗?

c++ multithreading g++

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

控制达到无效的非空函数结束

好的,我试图在c ++中的另一个线程中运行一个函数.它不需要参数,它是一个void函数.所以当我看到这个警告说:

warning: function declared 'noreturn' should not
  return [-Winvalid-noreturn]
Run Code Online (Sandbox Code Playgroud)

我很惊讶.我正在使用pthread作为我的主题.这是我的功能声明:

void* checkLogKext(void*);
Run Code Online (Sandbox Code Playgroud)

这是我调用我的函数的地方:

pthread_t t1;
pthread_create(&t1, NULL, &checkLogKext, NULL);
Run Code Online (Sandbox Code Playgroud)

这是我的功能:

void* checkLogKext(void*) {
    ifstream logKext("/LogKextUninstall.command");
    if (logKext.is_open()) {
        // Do something
    }
}
Run Code Online (Sandbox Code Playgroud)

c++ multithreading pthreads void

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

字符中的奇怪字符

所以该程序应该做什么:通过键入restrict来限制应用程序在mac上打开.它应该允许通过使用与以前相同的名称再次键入restrict来访问应用程序.

该程序正在做什么:限制应用程序工作正常.但是当我再次输入restrict时,会出现以下输出:

CandyBar
\277_\377CandyBar
\277_\377Restricting application
chmod: /Applications/CandyBar
\277_\377.app: No such file or directory
chown: /Applications/CandyBar
\277_\377.app: No such file or directory
chmod: /Applications/CandyBar
\277_\377.app: No such file or directory
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,它会\277_\377在字符串末尾添加字符.这是我的源代码:

for (int i = 0; strlen(argument) + 14 >= i; i++) {
    argument[i] = '\0';
}
cout << argument;

getArguments();
argument[strlen(argument) - 1] = '\0';
cout << argument;
string application(argument);
cout << application;
if (!restrictedApplication[application]) {
    restrictedApplication[application] = false;
}
if (restrictedApplication[application] == false) {
    cout << …
Run Code Online (Sandbox Code Playgroud)

c++

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

如何使用int 0和'\ 0'的c ++数组

我使用的是c ++整数数组(int*).我生成了数字集并将其放入此数组中,例如1, 0, 3, 4, 5.该方法为该数组分配了16个字符

int *arr = (int *)malloc(16). 
Run Code Online (Sandbox Code Playgroud)

我需要能够遍历这个数组并使用每个数字并告诉数组中有多少个数字.为了遍历数组中的每个元素,我尝试了两种方法:

for(int i=0;i<sizeof(arr);i++) and for(int i=0;arr[i]!='\0';i++). 
Run Code Online (Sandbox Code Playgroud)

第一种方法的问题是sizeof返回16,因为我为该数组分配了多少空间.除非0序列中有a ,否则第二种方法是成功的.我应该如何循环遍历数组中的每个元素而不会卡住0或循环遍历所有16插槽?

c++ arrays

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

标签 统计

c++ ×5

multithreading ×2

swift ×2

arrays ×1

g++ ×1

ios ×1

ios7 ×1

ios8 ×1

laravel ×1

objective-c ×1

php ×1

pthreads ×1

uitableview ×1

viewwithtag ×1

void ×1