小编viv*_*ain的帖子

为什么sizeof派生类是8?

#include <iostream>
using namespace std;

class Empty
{};


class Derived : virtual public Empty
{
    char c;
};

int main()
{
    cout << "sizeof(Empty) " << sizeof(Empty) << endl;
    cout << "sizeof(Derived) " << sizeof(Derived) << endl;


    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么尺寸即将到来8我认为它应该是9,如果我将'c'声明为整数然后它即将到来的8 Cany你请解释我的逻辑

c++

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

日历日期的算术用C或C++(在给定日期添加N天)

我一直在考虑一个日期,我正在采取像输入(日,月,年): 12, 03, 87.

现在我需要找出n几天之后的日期.

我已为此编写代码,但效率不高.能不能告诉我任何好的逻辑,它运行得更快,复杂性更低.

#include <stdio.h>

static int days_in_month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int day, month, year;

unsigned short day_counter;

int is_leap(int y) {
    return ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0);
}

next_day()
{
    day += 1; day_counter++;
    if (day > days_in_month[month]) {
        day = 1;
        month += 1;
        if (month > …
Run Code Online (Sandbox Code Playgroud)

c c++ date date-arithmetic

6
推荐指数
2
解决办法
3万
查看次数

WCF 中的 MaxReceivedMessageSize 错误

由于我是 WCF 的新手,请帮助我。我收到此错误。我在互联网上搜索过这个问题,我有很多解决方案,但是当我应用这些解决方案时。我面临的一些新问题。所以请给我一个有效的解决方案。

已超出传入邮件的最大邮件大小配额 (65536)。要增加配额,请在适当的绑定元素上使用 MaxReceivedMessageSize 属性。

服务 Web.config 文件。

<system.serviceModel>
<bindings>
  <basicHttpBinding>
    <binding name="WSHttpBinding_IService1" maxBufferSize="2147483647"
      maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    </binding>
  </basicHttpBinding>
</bindings>
<services>
  <service name="WcfServiceZone_Store.Service1" behaviorConfiguration="metadataBehavior">
    <!-- Service Endpoints -->
    <endpoint address="" binding="wsHttpBinding" contract="WcfServiceZone_Store.IService1">
      <identity>
        <dns value="localhost"/>
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="metadataBehavior">
      <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- …
Run Code Online (Sandbox Code Playgroud)

wcf wcf-binding wcf-security wcf-data-services

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

Javascript警报在asp.net的更新面板中不起作用

我正在研究asp.net Web应用程序.我有一个UpdatePanel,表中有一些表,其中包含一些TextBox中的数据.

我在UpdatePanel中也有一个保存按钮所以当我单击Save Button时,我想将这些数据保存到数据库中.

到目前为止工作正常.

但我想向用户显示警告消息,表明信息已成功保存.我正在使用javascript这个目的,但Javascript无法正常工作.所以这可以使用javascript实现所需的功能,如果是,那么请指导我或如果有任何其他替代方法,除了这个,请让我知道.

谢谢,Vivek

javascript c# asp.net updatepanel

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

C#中的字节数组到字符串

作为C#的新手,我遇到了一个非常基本的问题.

我正在读一个文本文件,其中包含一些数据(例如"hello")我正在读取此数据,如下面提到的代码.

System.IO.Stream myStream;
Int32 fileLen;
StringBuilder displayString = new StringBuilder();

// Get the length of the file.
fileLen = FileUploadId.PostedFile.ContentLength;

// Display the length of the file in a label.
string strLengthOfFileInByte = "The length of the file is " +
fileLen.ToString() + " bytes.";

// Create a byte array to hold the contents of the file.
Byte[] Input = new Byte[fileLen];
// Initialize the stream to read the uploaded file.
myStream = FileUploadId.FileContent;

// Read the file into …
Run Code Online (Sandbox Code Playgroud)

c# bytearray

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

为什么第二个程序的输出与第一个程序不同?

返回对调用该函数的对象的引用时,返回的引用可用于链接单个对象上的函数调用.

在这里,我正在应用相同的概念.但是如果我以不同方式初始化对象,我会得到不同的输出.

第一个例子:

#include<iostream>
using namespace std;

class Test
{
private:
  int x;
  int y;
public:
  Test(int x = 0, int y = 0) { this->x = x; this->y = y; }
  Test &setX(int a) { x = a; return *this; }
  Test &setY(int b) { y = b; return *this; }
  void print() { cout << "x = " << x << " y = " << y << endl; }
};

int main()
{
  Test obj1(5, 5);

  // …
Run Code Online (Sandbox Code Playgroud)

c++

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

C#中字典中的字典

我正在创建一个字典,它有一个键作为字典.这是两个词典的声明.

Dictionary<Dictionary<Int64,string>, Int64> AccountTypeDic = new Dictionary<Dictionary<Int64, string>, Int64>();
Dictionary<Int64,string> IdName = new Dictionary<Int64,string>(); 
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试将数据添加到Dictionary中时,我得到了异常.

执行:已添加具有相同键的项目.所以请告诉我如何将数据添加到Dictionary中.

if (sqlDataReader.HasRows)
{
    while (sqlDataReader.Read())
    {
        IdName.Clear();
        IdName.Add(Int64.Parse(sqlDataReader["ID"].ToString()), 
           sqlDataReader["ACCOUNT_NAME"].ToString());
        AccountTypeDic.Add(IdName,
           Int64.Parse(sqlDataReader["SEQUENCE_ID"].ToString()));
    }
}
Run Code Online (Sandbox Code Playgroud)

sqlDataReader具有所有字段ID,帐户名和序列码.

请不要建议我应该使用其他一些数据结构.我只是想知道如何以这种方式处理它.

c#

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

将锯齿状的字符串数组转换为C#中的字符串列表

我想转换string[][]List<List<string>>.

例如.

List<List<string>> listOfListReturned = new List<List<string>>();
string[][] twoDArrOfString = new string[2][];
Run Code Online (Sandbox Code Playgroud)

我想转换twoDArrOfStringlistOfListReturned

请建议,怎么做?

此致,Vivek

.net c#

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

为什么这个程序没有输出什么?

#include <iostream>
using namespace std;

int main()
{
   int test = 0;
   cout << (test ? "A String" : 0) << endl;

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++

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