小编Sea*_*ght的帖子

如何按用户给出的完整路径打开文件?

我写了这段代码.我想向用户询问文件的完整路径,然后转到该路径并打开文件.但不幸的是程序无法找到该文件.例如,我在这个路径G:\ project 2 \newfile中创建了一个文件但是当我在c ++控制台中输入它时,它说"打开文件时出错".我真的需要解决这个问题.请帮我解决一下这个.谢谢

#include <iostream>
#include <fstream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main()
{
    string address;
    cout << "Enter the full path of the file" << endl;
    cin >> address;
    ifstream file(address.c_str());

    if (!file) {
        cout << "Error while opening the file" << endl;
        return 1;
    }

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

c++ file

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

cd命令不能与execvp一起使用

#include <stdio.h>
#include <sys/types.h>
#include <string.h>

int main()
{
    char *ip;
    char *temp[10];
    pid_t pid;

    pid = fork();

    if (pid == 0) {
        int i = 0;

        do {
            gets(ip);

            temp[0] = strtok(ip, " ");
            while (temp[++i] != NULL) {
                temp[i] = strtok(NULL," ");
            }

            pid_t pid2;

            pid2 = fork();
            if (pid2 == 0) {
                execvp(temp[0], temp);
            }
        } while(strcmp(temp[0], "quit"));

        if (!strcmp(temp[0],"quit")) {
            return;
        }
    } else if (pid < 0) {
        fprintf(stderr,"error in creating child");
    } else if …
Run Code Online (Sandbox Code Playgroud)

c linux

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

为除尖括号外的非字符之外的每个单词添加标签

我正在处理包含图像标记和新行标记的文本段落.目标是通过将所有单词charachter的颜色更改为白色来使所有非单词charechter显示清楚.我正在使用java作为编程语言.我想使用正则表达式,但问题它改变了图像标签内的单词charechters.

String RegEx = "\\w|[àÀâÂäÄáÁéÉèÈêÊëËìÌîÎïÏòÒôÔöÖùÙûÛüÜçÇ’ñ]";

try {
    Pattern mypattern = Pattern.compile(RegEx, Pattern.CASE_INSENSITIVE);
    Matcher myMatcher = mypattern.matcher(sentence);
    int offset = 0;
    while (myMatcher.find()) {
        int start = myMatcher.start() + offset;
        int end = myMatcher.end() + offset;
        sentence = sentence.substring(0, start) + "<font color=\"white\">" + sentence.substring(start, end) + "</font>" + sentence.substring(end, sentence.length());
        offset += 28;
    }
} catch (Exception e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

所需结果的例子.输入: Most implementations<img title="hello:" alt="hello:{}" src="http://images.doctissimo.fr/hello.gif" class="wysiwyg_smiley" /> provide ASDF as a module, and you can …

html java regex

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

PHP &gt; 下载 ZIP:网络错误

我的 php 代码有一个大问题,我使用 html 表单来获取“文件名”,工作完美,但我的问题是:当我启动下载时,所有浏览器都下载 zip 文件,并出现网络错误,例如:578ko / 600ko:网络错误。

<?php
$dir = "lol/"; // trailing slash is important
$file = $dir .$_POST['filename'] ;

if (file_exists($file)) {
    header('Pragma: public');
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Transfer-Encoding: binary");
    header("Content-type: application/zip");
    header('Content-Disposition: attachment; filename='.basename($file));
    header('Cache-Control: must-revalidate');
    header('Content-Length: ' . filesize($file));

    readfile($file);

} else {
    echo "Le fichier $file n'existe pas.";
}
exit;
?>
Run Code Online (Sandbox Code Playgroud)

php

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

如果在Page_Load()内调用DataBind(),则SqlDataSource不执行更新

如果我将GridView(通过DataSourceID属性)绑定到SqlDataSource并设置SelectCommand和UpdateCommand属性,那么一切都很完美.

但我注意到,如果我,无论出于何种原因,还在Page_Load()中手动调用DataBind(),那么SqlDataSource不执行任何更新,即使当GridView的Update按钮是SqlDataSource.Updating和SqlDataSource.Updated事件时也会触发点击.

有人可以解释为什么不发生更新?

asp.net data-binding gridview sqldatasource

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

铸造成本?

我在Dictionary<string, Dictionary<string, string>>被调用的id2key_value中有一个由哈希(ID)映射的键/值对.您可以将此视为用行表示类似数据库的表的一种方法.

我添加了一些辅助函数来通过执行转换来简化一些基本数据类型的使用,比如

public int GetInt(string id, string key)
{
    int value = 0;
    bool success = int.TryParse(map[id][key], out value);

    if (success)
        return value;
    else
        throw new InvalidOperationException(
            "Trying to obtain a non-integer value with GetInt().");
}
Run Code Online (Sandbox Code Playgroud)

好吧,当我想出一个"cast-cache"的想法时,我觉得我很聪明,它基本上保存了已经解析过的对象,所以我可以跳过对int,bool,DateTime等字符串的解析,以及只需将它们从缓存中转换为适当的数据类型.喜欢,

public int GetInt(string id, string key)
{
    if (cast_cache.ContainsKey(id) && cast_cache[id].ContainsKey(key))
        return (int) cast_cache[id][key];

    int value = 0;
    bool success = int.TryParse(map[id][key], out value);

    if (success)
    {
        this.AddToCache(id, key, value);

        return value;
    }
    else
        throw new InvalidOperationException(
            "Trying to …
Run Code Online (Sandbox Code Playgroud)

c# caching casting

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

如何使用DOMDocument获取标记内容?

说这是HTML吗?

<html>
<body>
<embed scr="...." attr="..."></embed>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我想匹配整个嵌入标签<embed scr="...." attr="..."></embed>.我怎么能这样做?

我到目前为止

$fragment = new DOMDocument();
$fragment->loadHTML($string);

$xp = new DOMXPath($fragment);
$result = $xp->query("//embed");
print_r($result->item(0));
Run Code Online (Sandbox Code Playgroud)

html php domdocument

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

PHP函数无法正常工作(回显字符串,简单)

我创建了一个允许我调试PHP脚本的函数,只要将variable($debug)设置为1:

function debug($msg) {
    if ($debug == 1) {
        echo $msg;
    } else {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

这样,在我的脚本顶部(在functions.php调用文件之前),我写道:

$debug = 1;
Run Code Online (Sandbox Code Playgroud)

启用调试,然后:

debug("Function executed: " . $data);
Run Code Online (Sandbox Code Playgroud)

在某些点上,以便我知道字符串值/在该点的任何内容,所需的响应是屏幕上显示的消息.

但是,无论$debug字符串的值是什么,我都看不到任何echo'd语句.

怎么能实现这一目标?

php debugging function

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

JavaFX 从任务返回值

我是一名新的 JavaFX 程序员,目前在从 JavaFX 任务获取结果时遇到问题。我想从任务中获取一个对象。这是我的简单代码。

public class MyClass
{
    public static void main(String[] args)
    {
        final MyTask task = new MyTask();

        Thread th = new Thread(task);
        th.start();

        MyObject result;

        task.addEventHandler(WorkerStateEvent.WORKER_STATE_SUCCEEDED,
            new EventHandler<WorkerStateEvent>() {
                @Override
                public void handle(WorkerStateEvent t) {
                    result = task.getValue();
                }
            });
    }
}

public class MyTask extends Task<MyObject>
{
    MyObject object;

    @Override
    protected MyObject call() throws Exception
    {
        // some basic processing
        return object;
    }
}
Run Code Online (Sandbox Code Playgroud)

我得到一个错误,结果对象应该是最终的,如果我这样做,那么我无法获得结果对象中的值。我试过在论坛和谷歌上搜索,但找不到答案。任何帮助将不胜感激。谢谢。

java javafx

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

CS50 - 被马里奥金字塔困住

一直在做 pset1“马里奥金字塔”,并陷入了有关打印“哈希”的部分,已经尝试了不同的方法,但是......什么也没有。具体来说,问题在于它定义“hs”值的位置。https://docs.cs50.net/problems/mario/more/mario.html这是关于问题 pset1

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    int h, s, hs, i;

    do {
        h = get_int("Height: ");
    } while (h < 0 || h > 23);

    for (i = 0; i < h; i++) {
        /* ignore 1 */
        if (i < 1) {
            printf("");
        } else {
            for (s = (h - i); s > 1; s--) {
                /* Spaces */
                printf(" ");
            }

            for (hs = 2; hs < h; hs++) { …
Run Code Online (Sandbox Code Playgroud)

c cs50

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