小编Dan*_*676的帖子

Python:它有一个argc参数吗?

我用C和C++编写了相同的程序(打开文本文件和显示内容).现在我在Python中做同样的事情(在Linux机器上).

在C程序中,我使用代码if(argc!= 2){//退出程序}

问题:Python中用于检查参数数量的内容

if (argc != 2) {
    /* exit program */
}
Run Code Online (Sandbox Code Playgroud)

当前输出:

./python names.txt =显示文本文件(正确)./ python nam =错误消息:从sys.ext行声明(正确)./ python =错误消息:从sys.ext行声明(错误:想要它是一个单独的错误消息,说明没有文件名输入)

python linux error-handling file-io arguments

69
推荐指数
3
解决办法
9万
查看次数

使用UDP进行Netcat流式传输

我可以让netcat使用TCP流式传输视频

  {server}  cat [movie].avi | nc [client ip address] 65535

  {client}  nc -l -p 65535 | mplayer -
Run Code Online (Sandbox Code Playgroud)

我尝试使用-u命令通过UDP发送,但这不起作用

  {server}  cat [movie].avi | nc -u [client ip address] 65535

  {client}  nc -u -l -p 65535 | mplayer -
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

streaming networking udp tcp netcat

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

PHP新行\n和\ r \n无效

  $rows = mysql_num_rows($result) ;
  for ($j=0 ; $j < 3 ; $j++) {
  for ($i=0 ; $i < 3 ; $i++) {
    $row = mysql_fetch_array($result) ;
    echo '<a href="image2.php?id='.$row['ID'].'">'."<img src='".$row['Image']."' />".'</a>' ;

  }
   echo "\r\n";
  }
Run Code Online (Sandbox Code Playgroud)

代码显示三组三个图像.我的理解是\ r \n和\n(双引号)应该创建一个新行.然而,它只是在图像之间插入一个空格.是callign\r \n错误的方式,还是使用错误的代码来确定新行(换行符)

示例(#=一张图片):

没有echo\r \n:#########使用echo\r \n:### ### ###

php newline line break

10
推荐指数
3
解决办法
3万
查看次数

Python Force python保持int变量的前导零

下面是一段代码,它是功能解密和加密程序的一部分.

while checkvar < maxvar: # is set to < as maxvar is 1 to high for the index of var
    #output.append("%02d" % number)
    i =ord(var[checkvar]) - 64 # Gets postional value of i
    i = ("%02d" % i)
    if (checkvar + 1) < maxvar:
        j =ord(var[(checkvar + 1)]) - 64 # Gets postional value of i
        j = ("%02d" % j)
        i = str(i) + str(j) #'Adds' the string i and j to create a new i
    li.append(int(i))
    checkvar …
Run Code Online (Sandbox Code Playgroud)

python variables int zero

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

USB 插入时自动运行

当存储程序的 USB 插入计算机时,是否可以使程序自动运行(执行)

我认为这是不可能的,因为我在互联网上进行了搜索,而且这种编码会带来安全风险

例如,我有一个用 C++ 编写的简单倒计时器(10 比 1)(在 Windows 上编译),当 USB(存储 .exe 文件的)插入计算机时,计时器将启动,而无需我手动执行。

c++ windows usb autorun execute

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

应用程序的C#时间延迟

我目前正在开发一个应用程序,我想实现一个时间延迟.我不想使用System.Threading.Thread.Sleep(x); 当我读到这个停止线程(UI冻结)

我目前编写的代码是:

public void atimerdelay()
{
    lblStat.Text = "In the timer";
    System.Timers.Timer timedelay;
    timedelay = new System.Timers.Timer(5000);
    timedelay.Enabled = true;
    timedelay.Start();
}
Run Code Online (Sandbox Code Playgroud)

我知道atimerdelay()确实被调用(使用lblStat),但它们没有5秒的延迟.我已经阅读了http://msdn.microsoft.com/en-us/library/system.timers.timer.aspx但我无法解释为什么上面的代码不起作用.

其他信息 - (为Hamlet Hakobyan添加)

该应用程序是一个"卡片检查器"应用程序(大学项目 - 不使用或存储真实信息).一旦用户填写了所有相关内容并单击"检查",就会调用验证方法列表.在调用其中任何一个之前,执行ping操作以确保计算机上有实时Internet连接.我想在ping和验证开始之间添加一点延迟.

c# timer delay

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

参数检查

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main (int argc, char* argv[])
{
    string STRING;
    ifstream infile;    
    STRING = argv[1];
    infile.open(argv[1]);   
    if (infile.fail())// covers a miss spelling of a fail name
    {
        cout << "ERROR. Did you make a mistake in the Spelling of the File\n";
        return 1;
    }
    else
    {
        while(!infile.eof())
        {
            getline(infile,STRING); // Get the line
            cout<<STRING + "\n"; // Prints out File line
        }   
        infile.close(); 
        return 0; 
    }
}
Run Code Online (Sandbox Code Playgroud)

除了一个问题,我已经让这个程序正常工作了

如果用户只运行没有文件名的程序(我认为被称为参数),例如./displayfile,那么我得到一个Segmentation错误

我如何修改我的代码,以便程序退出时出现"添加文件名"的错误消息

我的第一个想法就是这样

if …
Run Code Online (Sandbox Code Playgroud)

c++ error-handling arguments file

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

C++以只读方式打开文件

我编写了一个打开文件的程序,然后逐行显示其内容(文本文件)

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main (int argc, char* argv[])
{
    string STRING;        
    ifstream infile;    
    infile.open(argv[1]);   
    if (argc != 2)  
    {
        cout << "ERROR.\n";
        return 1;
    }
    if(infile.fail())
    {
        cout << "ERROR.\n";
        return 1;
    }
    else
    {
        while(!infile.eof())
        {
            getline(infile,STRING); 
            cout<<STRING + "\n"; 
        }   
        infile.close(); 
        return 0; 
    }
}
Run Code Online (Sandbox Code Playgroud)

我需要添加什么才能使文件成为只读文件?

(infile.open(argv[1])我猜哪里去了)

c++ file-io

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

使用换行符将文本转储到文件

private void btnDump_Click(object sender, EventArgs e)
{
    using (StreamWriter sw = new StreamWriter("E:\\TestFile.txt"))
    {
        // Add some text to the file.
        sw.WriteLine(txtChange.Text);
    }
}
Run Code Online (Sandbox Code Playgroud)

这会将txtChange的文本转储到文本文件中.txtChange是一个富文本框,其中包含换行符(换行符).

当用户单击"转储"按钮时,所有文本都被转储但不在新行上.

例如txtChange看起来像

1
2
3
4
Run Code Online (Sandbox Code Playgroud)

倾销文本看起来像 1234

如何格式化文本转储以使文本在新行上?

c# file-io textbox dump line

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

C子系统中的Hello World程序

#include <stdio.h>
#include <stdlib.h>

void message(char m)
{
print("Hello\n");
}

int main()
{
message(m);    
}
Run Code Online (Sandbox Code Playgroud)

我尝试编译时出现错误消息

danielc@Ubuntu11:$ gcc Messagef.c -o Messagef
    Messagef.c: In function ‘main’:
    Messagef.c:11:9: error: ‘m’ undeclared (first use in this function)
    Messagef.c:11:9: note: each undeclared identifier is reported only once for each function it appears in
Run Code Online (Sandbox Code Playgroud)

我知道这是一个"愚蠢"的错误,但我只是看到哪里出错了

c subroutine

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

文件系统观察程序具有用户确定的路径?

如何让文件系统观察者观看在运行时选择的路径,例如用户可以输入C:\ Users\User\Desktop \

我试过使用一个文本框和一个按钮,点击它设置路径

    fileWatcher.Path = Convert.ToString(txtFileWatcherPath);
Run Code Online (Sandbox Code Playgroud)

这构建并运行但输入的任何路径都会导致程序崩溃(单击按钮后)

请注意,在这个早期阶段我不关心错误处理.

c# filesystemwatcher runtime path

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

c#键按下触发按钮单击

private void btnBrowserGo_Click(object sender, EventArgs e)
{
    browser.Navigate(txtBrowserURL.Text);
}
Run Code Online (Sandbox Code Playgroud)

上面的代码将浏览器定向到文本框中的URL地址.如果用户在键入URL时按下以太键,我希望也会发生此事件.我有这个代码(下面),但不知道如何调用上面的代码

private void txtBrowserURL_KeyPress(object sender, KeyPressEventArgs e)
{
    if (e.KeyChar == (char)13)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

c# events winforms

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