小编abe*_*nky的帖子

简单的线程在c ++中工作

我正在创建一个简单的C++程序来询问用户在主线程中的华氏度,然后在另一个线程中将此值转换为Celsius.

但我继续得到一个错误.此错误保持不变

visual studio 2008\projects\cs1\cs1\cs1.cpp(16):错误C2143:语法错误:缺少';' 在'='之前

此问题有时会消失,但不会出现运行时异常.我正在使用Visual Studio 2008,Windows XP.

谢谢-Sunny Jain

#include "stdafx.h"
#include "stdafx.h"
#include "windows.h"
#include "stdlib.h"
#include "stdio.h"
#include "process.h"
#include "conio.h"
#include "iostream"
using namespace std;

bool flag= false;

void calculateTemperature_DegreeCelcius(void * Fahrenheit)
{
    float far;
    far=*((float*) Fahrenheit);
    float celcius = (5.0/9.0)*(far - 32);
    cout << "\nDegree Celcius :";
    cout << celcius;  
    flag = true;
}


int _tmain(int argc, _TCHAR* argv[])
{
    float temp_Fahrenheit;

    while(true){
        cout << "\nEnter Degree Fahrenheit value you want to convert …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading

0
推荐指数
2
解决办法
866
查看次数

C编译器bug(浮点运算)?

#include<stdio.h>

int main()
{
    double fract=0;
    int tmp;

    //scanf("%lf",&fract);
    fract=0.312;
    printf("%lf",fract);
    printf("\n\n");
    while(fract>0){
        fract*=(double)10;
        printf("%d ",(int)fract);
        fract-=(int)fract;
    }
    getch();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这段代码的输出为:312

但是somehing不对..我正在使用devcpp 4.9.9.2编译器......

c floating-point

0
推荐指数
3
解决办法
387
查看次数

C中的问题使用记忆

请帮助:)操作系统:Linux

在"sleep(1000);"中,此时"top(显示Linux任务)"给我写了7.7%MEM使用.valgrind:没发现内存泄漏.

我明白了,写得正确,所有malloc结果都是NULL.但为什么在这个时候"睡觉"我的程序不会减少记忆?遗失了什么?

抱歉我的英文不好,谢谢


~ # tmp_soft
For : Is it free??  no
Is it free??  yes
For 0 
For : Is it free??  no
Is it free??  yes
For 1 
END : Is it free??  yes
END 

~ #top
  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                
23060 root      20   0  155m 153m  448 S    0  7.7   0:01.07 tmp_soft    
Run Code Online (Sandbox Code Playgroud)

完整来源:tmp_soft.c

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

struct cache_db_s
{
 int       table_update;
 struct    cache_db_s …
Run Code Online (Sandbox Code Playgroud)

c linux malloc free cc

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

发送两个字符串,但通过tcp接收一个

Hy家伙,这就是我的客户端和服务器代码的样子:

客户:

         TcpClient client = new TcpClient();
         client.Connect(IPAddress.Parse("192.168.1.12"), 5004);
         NetworkStream stream = client.GetStream();

         string username = loginName_txt.Text;
         byte[] message = Encoding.ASCII.GetBytes(username);
         stream.Write(message, 0, message.Length);
         loginName_txt.Clear();

         string password = password_txt.Text;
         byte[] message1 = Encoding.ASCII.GetBytes(password);
         stream.Write(message1, 0, message1.Length);
         password_txt.Clear();

         stream.Close();
         client.Close();
Run Code Online (Sandbox Code Playgroud)

服务器:

        TcpClient mClient = (TcpClient)client;
        NetworkStream stream = mClient.GetStream();

        byte[] message = new byte[1024];
        int recv = stream.Read(message, 0, message.Length);
        username = Encoding.ASCII.GetString(message, 0 , recv);
        updateUI("Username: " + Encoding.ASCII.GetString(message, 0, recv));

        byte[] message1 = new byte[1024];
        int recv1 = stream.Read(message1, …
Run Code Online (Sandbox Code Playgroud)

c#

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

如何在C#中组合两个整数?

假设我有以下代码:

int digit1 = 1;
int digit2 = 3;
Run Code Online (Sandbox Code Playgroud)

我需要组合两个整数,导致浮点数等于,在这种情况下,13.0f.这可能很容易,因为我是C#的新手并从一本书中学习它,但它是如何完成的?

例:

int digit1 = 3;
int digit2 = 6;
float result = combine_integers (digit1, digit2);
// result = 36
Run Code Online (Sandbox Code Playgroud)

注意:
我实际上并不需要一个功能.我只是为了这个例子而这样做了.

c# floating-point int

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

为什么我的变量没有初始化?

我只是从c转到C++,我正在尝试构建一个计算器.Int'结果'不会通过数学运算初始化.逻辑是,根据操作'',将有一个不同的值分配给'结果'.这似乎不起作用.

#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;

int main ()
{
    int n1, n2;
    char s,r;
    int result = 0;
    cout<< "Enter a calculation? (y/n)"<<endl;
    cin>>r;
    while(r=='y')
    {
        cout <<"Enter the first number"<<endl;
        cin>>n1;
        cout<<"Enter the operator"<<endl;
        cin>>s;
        cout<<"Enter the second number"<<endl;
        cin>>n2;

        if ('s' == '*')
        {
            result = n1*n2;
        }
        if ('s' =='+')
        {
            result = n1+n2;
        }

        if ('s' =='-')
        {
            result = n1-n2;
        }

        if ('s' =='/')
        {
            result = n1/n2;
        }
        cout << result<<endl;
        cout<< …
Run Code Online (Sandbox Code Playgroud)

c++ initialization

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

数学运算总是返回 0 c#

我有计算百分比并返回 int 值的 c# 程序,但它总是返回 0。

我已经编写了 16 个基本小时的代码,所以如果您发现其中的错误,我将不胜感激。

我调试了我的代码,发现该值被正确传递。

private int returnFlag(int carCapacity, int subscribers)
{
    int percentage = (subscribers / carCapacity)*100;
    return percentage;
}
Run Code Online (Sandbox Code Playgroud)

c#

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

连续,正整数的总和

我想总结连续的正整数(在每个负值开始一个新的总和)

输入:

int[] input = new int[] { 1, 2, 3, -1, 1, 3, -2, 3, 4 };
Run Code Online (Sandbox Code Playgroud)

输出:

output = { 6,4,7 }; // 1+2+3=6, 1+3=4, 3+4=7
Run Code Online (Sandbox Code Playgroud)

我尝试过类似input.Where(x => x > 0).Sum();但不起作用的东西

c# linq

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

回文编程

问题是

回文是在两个方向上读取相同的字符串,例如,赛车,眼睛等.编写程序,提示用户输入字符串并使用递归函数来确定给定输入是否为回文

到目前为止我已经做到了这一点,但它不是工作的人:

#include<stdio.h>
#include<conio.h>
#include<string.h>// to save string

int isPalindrome(char*str);

int main (void)
{
    int result;
    char str[50];

    printf("\n pls enter string; \n");
    gets(str);
    result = isPalindrome(str);

    if(result ==1) 
    {
        printf("\n input string in a palindrome string ");
    }
    else
    {
        printf(" not a palindrome");
    }

    getch();

    return 1;
}

int isPalindrome(char*str)
{
    static int length = strlen(str);

    if(length<1)
    {
        return 1;
    }

   if(str[0]=str[lenght - 1])
   {
       length-=2;
   }

   return isPalindrome(str + 1)
}


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

c++

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

带有abs()的C++代码无法编译

代码如下.代码不能在在线编译器上编译,我不知道为什么.它简短而且不言自明,请查看下面的详细信息.

#include <iostream>
#include <cmath> 

using namespace std;
int N;

int distance(int a, int b){
    if(abs(a-b) > N/2){
        return N - abs(a-b);
    }
    return abs(a-b);
}

bool test(int x, int y){
    if(distance(x,y) <=2){
        return true;
    }
    return false;
}

int main()
{
    N = 2;
   cout << "Hello World" << endl; 
   cout << test(3,4) << endl;
   return 0;
}
Run Code Online (Sandbox Code Playgroud)

错误信息如下:

In file included from /usr/include/c++/4.8.3/bits/stl_algobase.h:65:0,                           
                 from /usr/include/c++/4.8.3/bits/char_traits.h:39,                              
                 from /usr/include/c++/4.8.3/ios:40,                                             
                 from /usr/include/c++/4.8.3/ostream:38,                                         
                 from /usr/include/c++/4.8.3/iostream:39,                                        
                 from main.cpp:1:                                                                
/usr/include/c++/4.8.3/bits/stl_iterator_base_types.h: In instantiation of 'struct …
Run Code Online (Sandbox Code Playgroud)

c++

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

C#性能问题

quandry是 - 以下两种方法中的哪一种执行最佳
目标 - 获得类型为Wrapper(下面定义)
标准的对象- 速度超过存储
号.记录 - 约1000-约2000,最大约6K
选择 - 动态创建对象或从字典
执行查找执行速度 - 每秒调用x次

注意 - 我需要首先提供工作代码,然后进行优化,因此如果任何理论家可以提供场景信息背后的一瞥,那么在我进行实际性能测试之前可能会有所帮助.

定义 -

class Wrapper  
{  
   public readonly DataRow Row;  
   public Wrapper(DataRow dr)  
   {  
      Row = dr;  
   }  
   public string ID { get { return Row["id"].ToString(); } }  
   public string ID2 { get { return Row["id2"].ToString(); } }  
   public string ID3 { get { return Row["id3"].ToString(); } }  
   public double Dbl1 { get { return (double)Row["dbl1"]; } }  
   // ... total …
Run Code Online (Sandbox Code Playgroud)

.net c# optimization performance high-availability

-8
推荐指数
2
解决办法
324
查看次数