小编Chr*_*tig的帖子

发布模式仍然依赖于MSVCP110D.dll(C++ MSVS)

我是C++编程的新手,刚刚完成了一个简单的计算器.我决定与我的朋友分享它,经过几次尝试,想出如何在发布模式下编译它.但是,即使在发布模式下,它仍然依赖于MSVCP110D.dll.我想知道是否有办法解决这个问题?

c++ visual-studio

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

从响应流中获取JSON数据并将其作为字符串读取?

我正在尝试从发送POST请求时收到的服务器读取响应.查看fiddler,它说这是一个JSON响应.如何使用C#Winforms将其解码为普通字符串,最好不使用外部API.如果您需要,我可以提供额外的代码/提琴手结果.

小提琴和乱码图像:

胡言乱语JSON

我试图在下面的代码中读取流:

Stream sw = requirejs.GetRequestStream(); 
sw.Write(logBytes, 0, logBytes.Length); 
sw.Close(); 
response = (HttpWebResponse)requirejs.GetResponse();
Stream stream = response.GetResponseStream(); 
StreamReader sr = new StreamReader(stream); 
MessageBox.Show(sr.ReadToEnd());
Run Code Online (Sandbox Code Playgroud)

c# json httpwebresponse winforms

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

处理的异常仍然被抛出?

我的代码:

public void CPUStats()
{
    var cpuCounter = new PerformanceCounter("Processor", "% Processor Time", 
                                                                     "_Total");
    var ramCounter = new PerformanceCounter("Memory", "Available MBytes");
    ramCounter.NextValue();
    cpuCounter.NextValue();
    System.Threading.Thread.Sleep(1000);
    string cpusage = cpuCounter.NextValue().ToString();
    string ramusage = ramCounter.NextValue().ToString();

    //Occurs here v
    try
    {
        //exception thrown here v
        cpuLabel.Invoke((MethodInvoker)(() => cpuLabel.Text = "CPU: " + 
                                   cpusage.Remove(cpusage.IndexOf('.')) + "%"));
    }
    catch(ArgumentOutOfRangeException)
    {
        cpuLabel.Invoke((MethodInvoker)(() => cpuLabel.Text = "CPU: " + 
                                                                 cpusage + "%"));
    }

    ramLabel.Invoke((MethodInvoker)(() => ramLabel.Text = "Free RAM: " + 
                                                             ramusage + "mb"));
}
Run Code Online (Sandbox Code Playgroud)

有时我的应用程序将在cpuLabel调用时停止并在我的代码中处理并修复它时抛出"ArgumentOutOfRangeException".我尝试增加激活激活CPUStats()的线程的计时器,但无济于事.

为什么会这样?

c# exception-handling exception try-catch

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

文件正被另一个进程使用 StreamWriter 使用

我的程序对我来说是练习,但是,当我尝试写入它找到的所有目录时,它崩溃了。

我尝试了以下方法:

  • 让它写入文件流而不是文件本身
  • 使用 File.Writealllines 使用 list<> (这有效,只是它完成了前五个,不再有)
  • FileStream.Write(subdir.ToCharArray())

我不明白为什么这不起作用,我做错了什么?

static void Main(string[] args)
{
    Method(@"C:\");
}

static void Method(string dir)
{
    //crash happens here v
    StreamWriter sw = new StreamWriter(@"C:\users\"+Environment.UserName+"\desktop\log.txt",true);

    foreach (string subdir in Directory.GetDirectories(dir))
    {
        try
        {
            Console.WriteLine(subdir);
            sw.Write(subdir);
            Method(subdir);
        }
        catch (UnauthorizedAccessException)
        {
            Console.WriteLine("Error");
        }
    }
  sw.Close(); 
}
Run Code Online (Sandbox Code Playgroud)

c# streamwriter

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

匹配受歧视的联合案例而不是内容

在 F# 中是否可以根据大小写而不是大小写内容来匹配受歧视的联合?例如,如果我想按 case 的元素过滤列表Flag,是否可以这样过滤?目前,我被迫使用三个独立的功能来按照我想要的方式进行过滤。这是我到目前为止所采用的方法:

type Option = 
 {Id : string
  Arg : string}

type Argument =
     | Flag of string
     | Option of Option
     | Unannotated of string

//This is what I'm going for, but it does not work as the "other" match case will never be matched
let LocateByCase (case:Argument) (args : Argument List) =
    args
    |> List.filter (fun x -> match x with
                             | case -> true
                             | _ -> false)

let LocateAllFlags args = …
Run Code Online (Sandbox Code Playgroud)

f# pattern-matching discriminated-union

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

带记录的F#类型推理奇数行为

我正在学习F#,我正试图解决为什么,当我用正确的类型覆盖推断类型时,它推断出一个不同的类型List.Filter.代码胜过千言万语:

type Account = 
{ account : int
  label : string }

type Journal = 
{ account : int
  period : string
  debit : int
  credit : int }

let outputJournal (journals: Journal List) (account:Account) =
    let filtered = List.filter (fun x -> x.account = account.account) journals
    filtered
Run Code Online (Sandbox Code Playgroud)

我需要根据指定的帐户过滤日记帐列表.但是,该outputJournal函数在journals传递给的参数下输出错误List.filter.错误如下:"类型不匹配.期望'帐户列表'但给出'列表日记'.类型'帐户'与类型'日记''不匹配.

我很困惑为什么会这样,因为我(或者我认为)清楚地试图过滤一份期刊清单.有没有办法我可以覆盖类型推断来做我的意思或以其他方式让我的意图更清楚的编译器(在任一记录中重命名帐户字段是一个选项,但我想避免它)?

非常感激.谢谢.

f# type-inference

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

输入字符串格式不正确C#

我很好奇为什么这会给我一个错误:

输入字符串的格式不正确.

发生此错误是因为屏幕是null因为它应该检查失败并且不会导致异常.

if (double.Parse(textDisplay.Text) >= -2147483647 & textDisplay.Text != null)
Run Code Online (Sandbox Code Playgroud)

c# string

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