小编dan*_*dan的帖子

C++使用getline()打印:释放的指针未在XCode中分配

我正在尝试使用std:getline()但遇到一个奇怪的运行时错误:

malloc:*对象0x10000a720的错误:未释放指针被释放*在malloc_error_break中设置断点以进行调试

这是产生此错误的代码:

//main.cpp
#include <iostream>
#include <sstream>

int main (int argc, char * const argv[])
{
   std::istringstream my_str("demo string with spaces");
   std::string word;

   while (std::getline(my_str, word, ' ')) {
        std::cout << word << std::endl;
   }
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

在每个单词之前我都会收到此错误.从评论中看起来似乎是OSX/XCode特定的错误.有什么提示吗?

更新: 错误仅在调试模式下打印.如果我在发布模式下构建此代码,一切都很好.

更新2: 可以在此处找到有关该问题的更多信息.

解:

_GLIBCXX_FULLY_DYNAMIC_STRING = 1

在目标信息构建选项卡中的预处理器宏中.

系统信息:

OSX 10.6.2 | XCode 3.2 | g ++ 4.2 | 调试i386的配置

c++ malloc macos xcode getline

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

AppleScript如何获得当前的显示分辨率?

我正在尝试根据鼠标光标的位置获取两个显示器的当前显示分辨​​率.

即,当鼠标光标在第一个显示器上时,我想获得该显示器的分辨率.

使用shell脚本我可以得到两个解决方案:

set screenWidth to (do shell script "system_profiler SPDisplaysDataType | grep Resolution | awk '{print $2}'")
Run Code Online (Sandbox Code Playgroud)

但我不知道哪个显示器目前处于"活动状态".

有任何想法吗?

applescript resolution

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

如何使用PHP登录Youtube?

我想使用youtube api通过此api调用获取用户新的订阅视频:

http://gdata.youtube.com/feeds/api/users/default/newsubscriptionvideos
Run Code Online (Sandbox Code Playgroud)

没有登录我得到这个回复:

User authentication required.
Error 401
Run Code Online (Sandbox Code Playgroud)

如何从php登录youtube?

php youtube api login youtube-api

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

Objective-C访问/更改多维数组中的数组元素(NSArray)

我正在尝试更改多维数组中的值,但收到编译器错误:

warning: passing argument 2 of 'setValue:forKey:' makes pointer from integer without a cast
Run Code Online (Sandbox Code Playgroud)

这是我的内容数组:

NSArray *tableContent = [[NSArray alloc] initWithObjects:
                [[NSArray alloc] initWithObjects:@"a",@"b",@"c",nil],
                [[NSArray alloc] initWithObjects:@"d",@"e",@"f",nil],
                [[NSArray alloc] initWithObjects:@"g",@"h",@"i",nil],
                 nil];
Run Code Online (Sandbox Code Playgroud)

这就是我试图改变价值的方式:

[[tableContent objectAtIndex:0] setValue:@"new value" forKey:1];
Run Code Online (Sandbox Code Playgroud)

解:

 [[tableContent objectAtIndex:0] setValue:@"new val" forKey:@"1"];
Run Code Online (Sandbox Code Playgroud)

所以数组键是一个字符串类型 - 有点奇怪,但很高兴知道.

arrays objective-c multidimensional-array

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

iPhone SDK - 如何将UIImage绘制到另一个UIImage上?

我有几个矩形图像(在横向和纵向模式下),并希望将它们绘制到透明的方形图像上,这样所有图像都会变成相同的大小而不会裁剪它们.我如何创建一个透明的UIImage并在顶部绘制另一个?

谢谢你的任何提示.

iphone drawing uiimage

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

如何在Debian Linux上为python 2.5安装SSL?

如何在Debian上为Python 2.5安装SSL?

我试过了:

sudo easy_install ssl
Run Code Online (Sandbox Code Playgroud)

但得到:

$ python setup.py build
looking for /usr/include/openssl/ssl.h
looking for /usr/include/krb5.h
running build
running build_py
running build_ext
building 'ssl._ssl2' extension
creating build/temp.linux-i686-2.5
creating build/temp.linux-i686-2.5/ssl
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I./ssl/2.5.1 -I/usr/include/python2.5 -c ssl/_ssl2.c -o build/temp.linux-i686-2.5/ssl/_ssl2.o
In file included from ssl/_ssl2.c:75:
./ssl/2.5.1/socketmodule.h:45:33: error: bluetooth/bluetooth.h: No such file or directory
./ssl/2.5.1/socketmodule.h:46:30: error: bluetooth/rfcomm.h: No such file or directory
./ssl/2.5.1/socketmodule.h:47:29: error: bluetooth/l2cap.h: No such file or directory
./ssl/2.5.1/socketmodule.h:48:27: error: bluetooth/sco.h: No …
Run Code Online (Sandbox Code Playgroud)

python installation ssl

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

C++如何使用和传递三维char数组?

我正在尝试构建一个char数组来存储函数的返回值.在以下函数中,数据存储在*****valv**中.如何构建外部变量来访问数据?

int credis_lrange(REDIS rhnd, const char *key, 
                   int start, int end, char ***valv) 
{
  int rc;

  if ((rc = cr_sendfandreceive(rhnd, CR_MULTIBULK, "LRANGE %s %d %d\r\n", 
                                key, start, end)) == 0) 
  {
    *valv = rhnd->reply.multibulk.bulks;
    rc = rhnd->reply.multibulk.len;
  }

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

解:

char **elements;

int size = credis_lrange(this->redis,"object_2",600,603,&elements);

for (int i=0; i<size;i++) {
    cout << "element: " << elements[i] << endl; 
}
Run Code Online (Sandbox Code Playgroud)

谢谢大家!

c++ multidimensional-array redis

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