我用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行声明(错误:想要它是一个单独的错误消息,说明没有文件名输入)
我可以让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)
有任何想法吗?
$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:### ### ###
下面是一段代码,它是功能解密和加密程序的一部分.
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) 当存储程序的 USB 插入计算机时,是否可以使程序自动运行(执行)
我认为这是不可能的,因为我在互联网上进行了搜索,而且这种编码会带来安全风险
例如,我有一个用 C++ 编写的简单倒计时器(10 比 1)(在 Windows 上编译),当 USB(存储 .exe 文件的)插入计算机时,计时器将启动,而无需我手动执行。
我目前正在开发一个应用程序,我想实现一个时间延迟.我不想使用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和验证开始之间添加一点延迟.
#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) 我编写了一个打开文件的程序,然后逐行显示其内容(文本文件)
#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])我猜哪里去了)
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
如何格式化文本转储以使文本在新行上?
#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:\ Users\User\Desktop \
我试过使用一个文本框和一个按钮,点击它设置路径
fileWatcher.Path = Convert.ToString(txtFileWatcherPath);
Run Code Online (Sandbox Code Playgroud)
这构建并运行但输入的任何路径都会导致程序崩溃(单击按钮后)
请注意,在这个早期阶段我不关心错误处理.
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# ×4
c++ ×3
file-io ×3
arguments ×2
line ×2
python ×2
autorun ×1
break ×1
c ×1
delay ×1
dump ×1
events ×1
execute ×1
file ×1
int ×1
linux ×1
netcat ×1
networking ×1
newline ×1
path ×1
php ×1
runtime ×1
streaming ×1
subroutine ×1
tcp ×1
textbox ×1
timer ×1
udp ×1
usb ×1
variables ×1
windows ×1
winforms ×1
zero ×1