小编Rim*_*nas的帖子

无法使用C#SSH.NET更改目录

当我使用SSH.NET库连接到服务器时,默认文件夹为/mif/stud3/2014/rira1874。当我执行

res = ssh.CreateCommand("cd existingFolder").Execute();
Console.WriteLine(res);
Run Code Online (Sandbox Code Playgroud)

它仍然保留在默认连接文件夹中。怎么了

完整代码:

public void ConnectWithPassword(string username, string password, string domain, int port)
        {
            bool i = true;
            using (var ssh = new SshClient(CreatePasswordConnectionInfo(username, password, domain)))
            {
                try
                {
                    ssh.Connect();
                    if (ssh.IsConnected)
                    {
                        while(i == true)
                        {
                            string res = Regex.Replace(ssh.CreateCommand("pwd").Execute(), @"\r\n?|\n", "");
                            Console.Write(res + ": ");
                            res = ssh.CreateCommand(Console.ReadLine()).Execute();
                            Console.WriteLine(res);
                        }
                    }
                    else {
                        Console.WriteLine("Not connected");
                    }
                    ssh.Disconnect();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Exception caught: {0}", e);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

c# linux ssh

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

动态开关案例

我试图做一个简单的开关情况下控制台菜单中的几个不同的用户:admin,moderator,和user.admin将有create, delete, modify, show功能,moderator- create, modify, show功能和user- create, show功能可供选择.

管理员开关案例:

if(userType == "admin")
{
    string i = Console.ReadLine();
    switch(i):
    case "create": Console.WriteLine("Created");
                   break;
    case "modify": Console.WriteLine("Modified");
                   break;
    case "delete":Console.WriteLine("Deleted");
                  break;
    case "show":Console.WriteLine("Showed");
                break;
    default: Console.WriteLine("Default");
             break;
}
Run Code Online (Sandbox Code Playgroud)

主持人开关案例:

if(userType == "moderator")
{
    string i = Console.ReadLine();
    switch(i):
    case "create": Console.WriteLine("Created");
                   break;
    case "modify": Console.WriteLine("Modified");
                   break;
    case "show": Console.WriteLine("Showed");
                 break;
    default: Console.WriteLine("Default");
             break;
}
Run Code Online (Sandbox Code Playgroud)

用户开关案例: …

c# switch-statement

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

使用单链表的结构

我一直想知道:

struct node
{
    int data;
    struct node *next;
}*head;
Run Code Online (Sandbox Code Playgroud)

我相信*head变量是链表的第一个指针,但为什么它写在结构括号之外?为什么我需要在整个结构之外写它?任何人都可以回答,因为我在整个链表中丢失了东西.如果它已经在整个"节点"结构中,为什么我们需要用"struct node"声明*next指针?

c singly-linked-list

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

只读取文本文件中整行的第一个整数

如果有这样的文本文件:

3       size of group
10     individual therapy time(min)
15     group therapy time(min)
25      new client probability percentage
500     individual therapy cost
300     group therapy cost
Run Code Online (Sandbox Code Playgroud)

有没有办法只读取文本行的第一个整数并跳转到其他行?

我尝试过的:

settingsFile >> groupSize >> trash >> trash >> trash;
settingsFile >> indTime >> trash >> trash >> trash;
settingsFile >> newClientProb >> trash >> trash >> trash >> trash;
settingsFile >> indTherapyCost >> trash >> trash >> trash;
settingsFile >> groupTherapyCost >> trash >> trash >> trash;
Run Code Online (Sandbox Code Playgroud)

在我看来,这不是一个阅读文本文件的好方法,因为如果我trash从文本文件中删除一个字符串,整个阅读将失败.

c++ file-io

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

Char数组到数学方程

我试图从给定的char数组中解析数学方程式,例如char equation[255] = "4+4";,我想将第一个数字复制到long number1,运算符到char oper第二个数字long number2.

我已经尝试了,sscanf(equation, "%d%c%d", &number1, &oper, &number2);但它只是得到第一个数字,无法提取运算符和第二个数字.

试过这个方法:

while (isdigit(equation[k]))
    {
        k++;
    }                   
oper = equation[k];
Run Code Online (Sandbox Code Playgroud)

但它仍然没有得到运营商.有没有更简单的方法来解析c ++中的方程?

c arrays parsing

-3
推荐指数
1
解决办法
730
查看次数

标签 统计

c ×2

c# ×2

arrays ×1

c++ ×1

file-io ×1

linux ×1

parsing ×1

singly-linked-list ×1

ssh ×1

switch-statement ×1