小编BLU*_*IXY的帖子

如何在F#上创建XNamespace?

C#示例:

XNamespace aw = "http://www.adventure-works.com";
Run Code Online (Sandbox Code Playgroud)

F#我是怎么写的?

我试着这样:

let ns : XNamespace = "URI ADDRESS";;
Run Code Online (Sandbox Code Playgroud)

F#说错误

xml f#

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

Fibonacci序列在python中工作,但不在c中?

我有以下python代码:

a, b = 1, 1
for i in range(0, 100):
    print a
    a, b = b, a + b
Run Code Online (Sandbox Code Playgroud)

它产生了这个:1 1 2 3 5 8等

我在c中写了同样的文章:

#include <stdio.h>
long long unsigned int a = 1, b = 1;
void main(){
    for(int i = 0; i < 100; i++){
        printf("%llu \n", a);
        a = b, b = a + b;
    }
}
Run Code Online (Sandbox Code Playgroud)

它产生了这个:1 1 2 4 8 16 32等

为什么c程序在使用完全相同的操作时会产生2的幂?

c python fibonacci

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

使用scanf阅读两个长句子

我想从输入中读取两个长句子,使用scanf()它们在两行中。

码:

int main() {
    char a[100], b[100];
    scanf("%[^\n]s", a);
    scanf("%[^\n]s", b);
    printf("%s\n%s", a, b);
}
Run Code Online (Sandbox Code Playgroud)

输入:

she is beautiful
That is a flower
Run Code Online (Sandbox Code Playgroud)

输出:

she is beautiful
Run Code Online (Sandbox Code Playgroud)

scanf()语句未读取第二个输入。

如何解决?

c string scanf

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

"getchar()"函数如何能够将多个字符作为输入?

这是C中的基本字符计数程序:

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

int main(){
    long nc = 0;

    while(getchar() != EOF)
        nc++;
    printf("%ld\n" , nc);
}
Run Code Online (Sandbox Code Playgroud)

当我输入"abcde"作为输入时,它显示值6(触发EOF测试后),换行符字符+1.但我怀疑的是getchar(),正如其名称本身所暗示的那样,只考虑了1个字符.但是当我一口气进入"abcde"时,它仍然有效.为什么会这样?我在这做什么问题?

c

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

为什么我的输入文件的最后一行运行了两次?

输入文件

Miller Andrew 65789.87 5
Green Sheila 75892.56 9
Sethi Amit 74900.50 6.1
Run Code Online (Sandbox Code Playgroud)
ifstream inFile;
ofstream outFile;
string laastName;
string firstName;
double salary;
double percent;
double new Salary;
double increase;

inFile.open("Ch3_Ex6Data.txt");
outFile.open("Ch3_Ex6Output.dat");

while(!inFile.eof()) {

    inFile >> lastName;
    inFile >> firstName;
    inFile >> salary;
    inFile >> percent;

    percent /= 100;
    increase = salary * percent;
    newSalary = increase + salary;

    outFile << firstName << " " << lastName << " ";
    outFile << setprecision(2) << fixed << newSalary << endl;

} …
Run Code Online (Sandbox Code Playgroud)

c++ file-io while-loop eof

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

在C++中隐式转换char []到char*

大小char[]number of char times sizeof(char),大小char*sizeof(pointer)- 指向第一个元素的指针.

sizeof(char[])打印number of char times sizeof(char)main(),在它的声明,但如果我通过这个数组的功能,其功能转换char[]char*和它的imposibble获得使用数组的大小sizeof(),

"void pr(char chr[])" is changed to "void pr(char chr*)"
Run Code Online (Sandbox Code Playgroud)

代码示例:

using namespace std;
void pr(char chr[])
{
    std::cout << "in pr(): " << sizeof(chr)<<"\n";
}
int main()
{
    char* c;
    char z[] = { 1,2,3,4,5,6,7,8,9};
    c = z;
    std::cout << "sizeof char* c in main(): " << sizeof(c) << "\n"; …
Run Code Online (Sandbox Code Playgroud)

c++ arrays pointers

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

具有多重继承的类的sizeof

首先,我知道sizeof取决于机器和编译器的实现.我使用的是Windows 8.1.x64,gcc 5.3.0.,没有标志传递给编译器.
我的大学讲座中有以下代码:

#include <iostream>
class A
{
    public:
        int a;
        int b;
        A(){ a = 1; b = 2; }
};

class S1 : public A {
    public:
        int x1;
        S1(){ x1 = 5;}
};

class S2 : public A {
    public:
        int x2;
        S2(){ x2 = 6;}
};

class S12 : public S1, public S2 {
    public:
       int x12;
       S12(){ x12 = 7;}
};

int main()
{
    std::cout << "S1: " << sizeof(A) << std::endl;
    std::cout << …
Run Code Online (Sandbox Code Playgroud)

c++

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

抓住并继续?C#

是一个寻求简单答案的简单问题。不需要代码作为演示。当我调用一个函数时,它返回一个异常并且整个函数停止。如何忽略异常并继续该功能?

c#

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

来自字符串的意外返回值

我试图从传递给getPhoneNumber(char [] str)的字符串中获取电话号码,但由于某种原因,每次运行代码时我都会附加一些随机字符,请我需要帮助.

源代码

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


char* getPhoneNumber(char str[]);

int main(){

  getPhoneNumber("AT+CMGR=5 \n+CMGR: \"REC READ\",\"+9349036332058\",\"samuel\",\"17/03/31,20:44:52+04\"\nHOW THINS fa OK");

  return 0;
}

char* getPhoneNumber(char str[]){

  char *temp = strchr(str, ',')+2;
  const unsigned short len1 = strlen(temp);

  printf("value in temp : %s\n\n",temp);

  char *strPtr = strchr(temp, '\"');
  const unsigned short len2 = strlen(strPtr);

  printf("value in strPtr : %s\n\n",strPtr);
  int phone_num_len = len1-len2;

  char phone_num[phone_num_len];

  strncpy(phone_num, temp,phone_num_len);

  printf("Phone number : %s",phone_num);

}
Run Code Online (Sandbox Code Playgroud)

我还打印出了tempstrPtr的各个值用于调试目的,但返回的值似乎没问题.程序的输出如下图所示.

在此输入图像描述

c runtime function

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

列表初始化带有2个char []指针的向量<string>

我正在从命令行运行C++ 11程序,如此

marco @ host $ ./program.out a bb ccc

用于生成可执行文件的.cpp文件如下所示:

#include<iostream>
#include<vector>
#include<string>

int main(int argc, char* argv[]){
  std::vector<std::string> strs = {argv + 1, argv + argc};
  std::cout << strs[2] << endl;
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,它输出ccc.我没想到,因为列表初始化程序只包含char*类型的两个元素.我之前看过这样的列表内容:

vector<string> strs = {"str1", "str2", ..., "strN"};
Run Code Online (Sandbox Code Playgroud)

但指针init对我来说是全新的.似乎指针被视为开始和结束迭代器.我的问题是,编译器如何知道从argv + 1迭代到argv + argc来初始化strs中的各个字符串?只是为了把事情放在上下文中,有没有办法在C中以类似的方式使用列表初始化来初始化char*数组?

c++ pointers

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

标签 统计

c ×4

c++ ×4

pointers ×2

arrays ×1

c# ×1

eof ×1

f# ×1

fibonacci ×1

file-io ×1

function ×1

python ×1

runtime ×1

scanf ×1

string ×1

while-loop ×1

xml ×1