我正在编写一个 TCL 程序,如下所示:
#!/usr/bin/tclsh
set fInp [open file1.txt r]
while {[gets $fInp line] >= 0} {
statement 1
statement 2
}
statement 3
statement 4
while {[gets $fInp line] >=0} {
statement 5
statement 6
}
close $fInp
Run Code Online (Sandbox Code Playgroud)
我原以为它能正常工作,但令我惊讶的是,第二个 while 循环根本没有被执行。我得出的结论是,我们无法使用相同的文件描述符(或通道)两次读取 TCL 中的文件
所以我关闭了 fInp 并使用 fInp2 再次打开该文件,它起作用了!
这种行为背后的原因是什么?还有其他方法吗?
谢谢
我希望多次获得用户输入并将输入数据存储在一个字符串中,直到输入"退出"退出输入.我认为for循环可以工作,但我不知道该怎么做.
我有一串数字作为用户输入收到.如何确定输入的最大数量?
例如,如果用户输入1236985,则最大数量为9.
我有这个DDUnitConverter用于货币转换的代码.
#import "DDUnitConverter.h"
#import "DDCurrencyUnitConverter.h"
- (void) convertCurrency {
DDUnitConverter *converter = [DDUnitConverter currencyUnitConverter];
NSNumber *from = [NSNumber numberWithInt:42];
NSNumber *to = [converter convertNumber:from fromUnit:DDCurrencyUnitUKPoundSterling toUnit:DDCurrencyUnitUSDollar];
NSLog(@"new value: %@", to);
}
Run Code Online (Sandbox Code Playgroud)
我想根据用户的选择设置fromUnit:和toUnit:参数.我该怎么办?
我正在写一个小函数,它检查输入的字符串是否是莫尔斯码.该函数应该执行类似"If" - "或"的操作."仅在Inputted_string中:"但我似乎无法找到在Python3上执行唯一操作的方法.我实现这一目前的方式是非常混乱,而不是非常Pythonic
if "-" in message:
# message might be morse code so check even more
if "." in message:
# Message IS morse code so return true
return True
else:
# TODO you can use a REGEX for the below things
if '--' in message:
# if the messsage contains only hyphens, then check to see if
# message contans hyphen only morse code by checking all hyphen
# only morse code against message
return True …Run Code Online (Sandbox Code Playgroud) 我开始为一个小型银行帐户程序编写代码,但我的if/else语句不起作用.在循环的顶部,我scanf用来获取有关下一个需要执行哪个选项的用户输入.第一个始终有效,但在此之后,始终会打印错误语句.
例如,用户类型1.印刷的是:
case 1
ERROR, please try again
Run Code Online (Sandbox Code Playgroud)
只有案例1应该打印,为什么错误信息也会打印?我尝试使用switch case语句,但也没有用.
这是我的代码:
char num = '7';
while (1) {
if(num == '7') {
printf("0. Exit\n1. Deposit\n2. Withdrawal\n3. Add account\n");
printf("4. Remove account\n5. Balance inquiry\n6. View accounts\n");
printf("Enter option: (0/1/2/3/4/5/6)\n");
scanf("%c", &num);
}
else if (num == '0') {
exit(0);
}
else if (num == '1') {
printf("case 1\n");
num = '7';
}
else if (num == '2') {
printf("case 2\n");
num = '7';
}
else …Run Code Online (Sandbox Code Playgroud) 我有一个类分配来使用Scanner读取数据.
import java.util.Scanner;
public class Project23
{
public static void main(String[] args)
{
// Declarations and instantiations.
Scanner scan = new Scanner(System.in);
String any = "";
boolean more = false;
double purchase = 0.0;
// Ask if user would like to run program?
System.out.print("Do you have any purchases? Y/N?: ");
// Ready value into string.
any = scan.nextLine();
System.out.println();
// If any is equal to y or Y it will set the value of more to true
// this runs …Run Code Online (Sandbox Code Playgroud) 如何使用c#在主窗口上获取提示以询问用户输入?我试过了
Console.Writeline("write something");
Run Code Online (Sandbox Code Playgroud)
&
string input = Console.Readline();
Run Code Online (Sandbox Code Playgroud)
但是这些命令在我的主窗口上不显示任何内容.我有一个图像,控制台提示的显示可能在它后面吗?
我希望在main()方法之外的方法中使用用户输入.
嘿家伙们想知道你是否可以帮我解决下面这段代码.我的程序正在输出一些奇怪的计算.
#include <iostream>
using namespace std;
int main()
{
int radius;
const double PI = 3.14159265;
float area;
float circumference;
cout << "Program to find the area and circumference of a circle\n\n\n";
cout << "Please enter the radius: ";
radius = cin.get();
area = PI * (radius * radius);
circumference = (2 * radius) * PI;
cout << "The area of your circle is " << area << ", the circumference of your circle is " << circumference <<"\n\n";
system("PAUSE"); …Run Code Online (Sandbox Code Playgroud) 我是 C++ 的新手,所以也许这是一个愚蠢的问题,但我编写了一个非常简单的温度转换程序。它看起来像这样:
#include <iostream>
int main() {
double tempf;
double tempc;
// Ask the user
std::cout << "Enter the temperature in Fahrenheit: ";
std::cin >> tempf;
// Conversion
tempc = (tempf - 32) / 1.8;
// Print Output
std::cout << "The temp is " << tempc << " degrees Celsius.\n";
}
Run Code Online (Sandbox Code Playgroud)
当我输入整数/浮点数作为输入时,它可以编译并运行良好。然而,出于好奇,我尝试输入一封信,预计会出现错误或某种失败。相反,编译后,我得到以下输出:
$ g++ temperature.cpp -o temp
$ ./temp
Enter the temperature in Fahrenheit: abc
The temp is -17.7778 degrees Celsius.
Run Code Online (Sandbox Code Playgroud)
有人能告诉我可执行文件从哪里获取输出吗-17.7778?这看起来像是一个任意数字,而不是数学输出。
如何在不硬编码我的用户名和密码的情况下自动登录 Facebook?
我想将几个整数作为输入,直到出现换行符('\n',而不是 EOF),然后将它们放入 anarray或 a 中vector。如何使用 C++ 独有的关键字来做到这一点?
如何从用户输入字符串中删除空格?我不能用.replace(" ","")吗?它对我不起作用.
我的代码:
>>>p=raw_input ("Enter phrase:\n")
>>>p.replace(" "."")
Run Code Online (Sandbox Code Playgroud)
它仍然输出用户输入短语WITH spaces ..我做错了什么?请帮助.
user-input ×13
python ×4
c++ ×3
c# ×2
c ×1
cocoa ×1
cocoa-touch ×1
input ×1
iostream ×1
java ×1
morse-code ×1
objective-c ×1
operators ×1
prompt ×1
python-3.x ×1
selenium ×1
stdin ×1
string ×1
tcl ×1
whitespace ×1