小编Ome*_*isk的帖子

C++ - 删除std :: string*; 堆腐败

我对C++内存管理比较陌生,而且我遇到了这个奇怪的堆损坏错误(在它之前加上Visual Studio中的自动断点).这是违规代码:

z_world::z_world(char* name)
{
    unsigned int i, skip;
    char tmp;

    //Load data from file
    std::string* data = loadString(name);

    //Base case if there is no world data
    tiles = NULL;

    w = 0;
    h = 0;

    if(data->length() > 0) {
        //Set up the 'tiles' array
        for(i = 0; i < data->length(); i++) {
            if(data->at(i) == '\n')
                h++;
            if(h == 0)
                w++;
        }
        tiles = new int[data->length()-h];

        //Load Data
        skip = 0;
        for(i = 0; i < data->length(); i++) {
            if(data->at(i) …
Run Code Online (Sandbox Code Playgroud)

c++ string memory-management

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

Python'in'运算符莫名其妙地失败了

我检查文件中某个单词的简单脚本似乎失败了,我似乎无法通过文档或搜索来解释它.代码如下.我相信我已经将它缩小到'in'运算符,因为打印代码本身并找到我正在寻找的单词而失败.如果好奇,这个脚本是在Quake源代码中找到某些关键字,因为我宁愿不查看30多个完整的源文件.任何帮助将不胜感激,谢谢!

import os

def searchFile(fileName, word):
    file = open(os.getcwd() + "\\" + fileName,'r')
    text = file.readlines()

    #Debug Code
    print text

    if(word in text):
        print 'Yep!'
    else:
        print 'Nope!'
Run Code Online (Sandbox Code Playgroud)

python

0
推荐指数
2
解决办法
1049
查看次数

标签 统计

c++ ×1

memory-management ×1

python ×1

string ×1