Tag: C#的

为什么这个程序被三个C ++编译器错误地拒绝?

编写一个我编写的C ++程序时遇到一些困难。 这个程序非常简单,据我所知,符合C ++标准中规定的所有规则。 我已经仔细阅读了ISO / IEC 14882:2003的全部内容。 该计划如下: 这是我在Visual C ++ 2010编译这个程序时收到的输出: c:\dev>cl /nologo helloworld.png cl : Command line warning D9024 : unrecognized source file type 'helloworld.png', object file assumed helloworld.png : fatal error LNK1107: invalid or corrupt file: cannot read at 0x5172 很沮丧,我尝试了g ++ 4.5.2,但同样没有帮助: c:\dev>g++ helloworld.png helloworld.png: file not recognized: File format […]

从ID为名称的json对象创build一个强types的c#对象

我正在尝试使用一个知名的在线会议提供商的API。 他们的一个API调用返回一个看起来像这样的对象。 { "5234592":{ "pollsAndSurveys":{ "questionsAsked":1, "surveyCount":0, "percentageSurveysCompleted":0, "percentagePollsCompleted":100, "pollCount":2}, "attendance":{ "averageAttendanceTimeSeconds":253, "averageInterestRating":0, "averageAttentiveness":0, "registrantCount":1, "percentageAttendance":100} }, "5235291":{ "pollsAndSurveys":{ "questionsAsked":2, "surveyCount":0, "percentageSurveysCompleted":0, "percentagePollsCompleted":0, "pollCount":0}, "attendance":{ "averageAttendanceTimeSeconds":83, "averageInterestRating":0, "averageAttentiveness":0, "registrantCount":1, "percentageAttendance":100} } } 我想在C#中使用强types对象,所以我可以处理这些数据。 我可以为pollsAndSurveys位和出席位创build对象,但我不知道如何处理id号,在这种情况下是5234592&5235291,这是会话的标识符。 public class AttendanceStatistics { [JsonProperty(PropertyName = "registrantCount")] public int RegistrantCount { get; set; } [JsonProperty(PropertyName = "percentageAttendance")] public float PercentageAttendance{ get; […]

C跳过一个函数的命令?

我正在编程一个模拟,当用户select创build一个新的标签时,用户应该input一个标签ID,标签的所有者和标签所代表的对象。 该程序正在做什么只是跳过命令,扫描所有者,我不知道为什么。 我的代码如下(function在iotlib.cpp中): iotlib.cpp #include <stdio.h> #include <stdlib.h> #include <math.h> #define MAX 20 struct tagInfo { char owner[MAX]; char object[MAX]; int id; }; struct tre //TRE = Tag Read Event { int id; char node[MAX]; int dx; }; void initTag(struct tagInfo tag[], int numTags) { for(int i=0; i<numTags; i++) { printf("Enter the tag ID number: […]

无法通过使用gsm调制解调器的System.IO.Ports通过C#代码发送短信

一个button,当点击,发送一个短信到在NumTxt文本框中input的号码,并发送SMSTxt文本框中input的文本。 在texbox ComPort中input的端口名称这是button单击事件的事件处理程序。 using System.IO.Ports; private void button1_Click(object sender, EventArgs e) { try { int mSpeed = 1; serialport.PortName = ComPort.Text; serialport.BaudRate = 96000; serialport.Parity = Parity.None; serialport.DataBits = 8; serialport.StopBits = StopBits.One; serialport.Handshake = Handshake.XOnXOff; serialport.DtrEnable = true; serialport.RtsEnable = true; serialport.NewLine = Environment.NewLine; Console.WriteLine("1a"); try { serialport.Open(); } catch (Exception) { MessageBox.Show("Try another […]

平方负指数的权力

我不确定平方的权力是否负指数。 我实现了以下只适用于正数的代码。 #include <stdio.h> int powe(int x, int exp) { if (x == 0) return 1; if (x == 1) return x; if (x&1) return powe(x*x, exp/2); else return x*powe(x*x, (exp-1)/2); } 查看https://en.wikipedia.org/wiki/Exponentiation_by_squaring没有帮助,因为下面的代码似乎是错误的。 Function exp-by-squaring(x, n ) if n < 0 then return exp-by-squaring(1 / x, – n ); else if n = 0 then […]

“在G ++ Cpp中未定义的引用”

似乎无法让错误消失。 错误如下。 我看了谷歌,仍然无法弄清楚。 这不像我对Cpp是新手,但是暂时还没有被愚弄。 奇怪的是它在Windows中使用G ++ … 错误: [泽@ fed0r! – – – ** _ _ *] $ g ++ main.cpp /tmp/ccJL2ZHE.o:在main函数中: main.cpp 🙁 .text + 0x11):未定义的引用“Help :: Help()” main.cpp 🙁 .text + 0x1d):未定义引用到`Help :: sayName()' main.cpp :(。text + 0x2e):未定义引用到`Help ::〜Help()' main.cpp 🙁 .text + 0x46):未定义引用到`Help ::〜Help()' collect2:ld返回1退出状态 main.cpp中 #include <iostream> #include "Help.h" using namespace […]

为什么划分两个整数不会得到一个浮点数?

任何人都可以解释为什么b在这里四舍五入时,我把它除以一个整数,虽然它是一个浮点数? #include <stdio.h> void main() { int a; float b, c, d; a = 750; b = a / 350; c = 750; d = c / 350; printf("%.2f %.2f", b, d); // output: 2.00 2.14 } http://codepad.org/j1pckw0y

scanf中的空间是什么意思?

#include <stdio.h> int main(int argc, char* argv[]) { char c; scanf(" %c", &c); printf("%c\n", c); return 0; } [root@test]# ./scanf a a [root@test]# ./scanf h h 这似乎总是匹配空间是否存在,为什么?

是否有一个原因Image.FromFile抛出一个无效的图像格式的OutOfMemoryException?

我正在编写捕获此OutOfMemoryException代码,并引发一个新的更直观的exception: /// … /// <exception cref="FormatException">The file does not have a valid image format.</exception> public static Image OpenImage( string filename ) { try { return Image.FromFile( filename ); } catch( OutOfMemoryException ex ) { throw new FormatException( "The file does not have a valid image format.", ex ); } } 这个代码是否可以被用户接受,或者OutOfMemoryException是故意抛出的?

string.Replace(或其他string修改)不起作用

对于下面的代码,我无法获取string。replace工作: someTestString.Replace(someID.ToString(), sessionID); 当我debugging和检查someID.ToString它有“108716307”和sessionID有“108716308” 不知道为什么这不会工作,如果someTestString是以下内容: "The:<br>Photo: <b><a href='myfoldert/108716305-1.jpg' target='_blank'>108716305-1.jpg</a> (originalphoto.gif)</b><br>Background Color: <b>223324</b>" 结果应该是这样的: "The:<br>Photo: <b><a href='myfoldert/108716305-1.jpg' target='_blank'>1087163085-1.jpg</a> (originalphoto.gif)</b><br>Background Color: <b>223324</b>" 但它不会改变。 点击我的代码后,someTestString的string保持不变。