小编438*_*427的帖子

在字符串中用一个字符替换另一个字符

我有如下数据:

A:B:C:D

我想替换Cwith数据(比方说Z),以便它看起来像

A:B:Z:D

我该怎么做?

excel replace extract formula delimiter

20
推荐指数
2
解决办法
8万
查看次数

priority_queue中第一个模板参数的用途是什么

对于std :: priority_queue,我假设第一个模板参数指定了类型,第二个模板参数应该是该类型的容器.例:

priority_queue<int, vector<int>> someQueue;
Run Code Online (Sandbox Code Playgroud)

但是,以下代码编译并似乎运行正常:

class SomeClass
{
};

int main()
{
    priority_queue <SomeClass, vector<int>> pq;
    int x = 9;
    pq.push(x);
    int t = pq.top();
    cout << t << endl;
    pq.pop();
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码是无效的(即给出UB)?

如果它有效 - someClass在priority_queue中使用的第一个模板参数(即)是什么.

c++

11
推荐指数
2
解决办法
463
查看次数

伪造子进程的日期/时间

在Unix系统上,是否可以伪造子进程的已知日期和时间?

即,想象一下:

$ date 
Fri Jun 28 10:50:35 CEST 2019

$ with_date 10/05/2019 date
Fri May 10 10:50:36 CEST 2019
Run Code Online (Sandbox Code Playgroud)

如何执行with_date命令?

典型的用例是测试与日期/时间相关的软件,模拟各种情况。

unix posix

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

C,计算空白空间的数量

我正在编写一个将空格替换为' - '(< - this character)的函数.我最终想要回复我做了多少改变.

#include <stdio.h>
int replace(char c[])
{
    int i, cnt;
    cnt = 0;
    for (i = 0; c[i] != EOF; i++)
        if (c[i]==' ' || c[i] == '\t' || c[i] == '\n')
        {
            c[i] = '-';
            ++cnt;
        }
    return cnt;
}

main()
{
    char cat[] = "The cat sat";
    int n = replace(cat);
    printf("%d\n", n);
}
Run Code Online (Sandbox Code Playgroud)

问题是,它正确地将字符串更改为"The-cat-sat"但是对于n,它返回值3,当它应该返回2.我做错了什么?

c

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

编译错误:无法打开预编译的header.pch-没有这样的文件或目录

我最近购买了Bjarne Stroustrup撰写的文章“编程:使用C ++的原理和实践”,并且一直在关注它。我目前停留在早期项目中,我需要输出一些文本字符串。在Windows 10 Lenovo Yoga 2 Pro笔记本电脑上使用Visual Studio Community 2015更新1,我尝试编译该项目,但遇到了以下错误:

“无法打开预编译的头文件:Debug \ Finding the Upstairs Bathroom.pch':没有此类文件或目录”。该项目的名称恰当地命名为“ Finding the Upstairs Bathroom.cpp”。这是代码:

// I have the headers "stdafx.h" as well as this specific header lib 
// Bjarne Stroustrup created and which I had linked
// called "../../std_lib_facilities.h", which contains the standard C++ lib functions.

(#) define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS 1

int main()`// Main function`

{  
    cout << "Take the key out of your right pants pocket\n"; // Outputs string of text

    cout << …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors visual-studio-2015

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

使用替换或替换更改日期格式

我正在从一个excel文件中读取数据并将数据写入另一个excel文件.

我的问题是源具有格式的日期,dd.mm.yyyy目标必须具有格式dd-mm-yyyy.

所以我搜索了SO并找到了这个答案用一个字符串替换另一个字符,这表明我可以使用substitute.

所以我尝试了这段代码:

For r = 1 To 10 
    myOutputSheet.Cells(6+r, 1).Value  = myInputSheet.Cells(r, 1).Value 'Date
    myOutputSheet.Cells(6+r, 1).Value  = substitute(myOutputSheet.Cells(6+r, 1), ".", "-")
Next
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

Microsoft VBScript runtime error: Type mismatch: 'substitute'
Run Code Online (Sandbox Code Playgroud)

我如何更改.-

更新

我也尝试过这个:

For r = 1 To 10 
    myOutputSheet.Cells(6+r, 1).Value  = myInputSheet.Cells(r, 1).Value 'Date
    replace(myOutputSheet.Cells(6+r, 1), 2, 1, "-")
    replace(myOutputSheet.Cells(6+r, 1), 4, 1, "-")
Next
Run Code Online (Sandbox Code Playgroud)

但是这给出了错误:

Microsoft VBScript compilation error: Cannot use parentheses when calling …
Run Code Online (Sandbox Code Playgroud)

excel vba

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

用逗号来理解post和pre增量

考虑下面的程序

#include <stdio.h>
void main(){
    int p = -8;
    int i = (p++, ++p);
    printf("%d\n", i);
}
Run Code Online (Sandbox Code Playgroud)

我无法理解输出为-6的原因.

p++在赋值语句执行后++p会增加,在此之前会增加-8到-7.

怎么i分配-6?

c

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

K&amp;R c编程书第2版,练习3-2,我写的一个细微的错误

写练习3-2的时候,转义符和转义符:遇到一个微妙的问题,想不通:

#include <stdio.h>
void escape(char s[], char t[]);
void unescape(char s[], char t[]);
int main(){
   char s[] = "we can run all the \n \t \n \t \t programs on it";
   char t[100];
   char m[100];
   int n = 0;
   escape(s, t);
   printf("%s\n", s);
   printf("%s\n", t);
   unescape(t, m);
   printf("%s\n", m);
}
void escape(char s[], char t[]){
   int i, j;
   for (i = j = 0; s[i] != '\0' ; i++){
   switch(s[i]){
      case '\n':
         t[j++] = '\\';
         t[j++] = 'n';
         break;
      case …
Run Code Online (Sandbox Code Playgroud)

c

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

动态分配的字符串填充了字符,结果为空字符串C.

int main(){
    char *c=(char*)malloc(4*sizeof(char));
    *c='a';
    c++;
    *c='b';
    c++;
    *c='c';
    c++;
    *c='\0';
    printf("%s",c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用此代码,我可以打印每个单个字符(例如printf("%c",*(--c));),但是当我尝试使用printf("%s",c);该程序打印整个字符串时,什么都不打印!为什么会这样?

c memory string malloc

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

递归代码退出,退出代码为 3221225477

我是 C++ 编程和 StackOverflow 的新手,但我对核心 Java 有一些经验。我想参加编程奥林匹克,我选择了 C++,因为 C++ 代码通常比同等的 Java 代码更快。

\n\n

我正在解决一些涉及分区级别的递归和 DP 的问题,我遇到了这个称为序列游戏的问题

\n\n

但不幸的是我的代码似乎不起作用。它退出时退出代码为 3221225477,但我无法从中获取任何信息。我记得 Java 在指出我的错误方面做得更好,但在 C++ 中我不知道发生了什么。顺便说一句,这是代码,

\n\n
#include <iostream>\n#include <fstream>\n#include <cstdio>\n#include <algorithm>\n#include <vector>\n#include <set>\nusing namespace std;\nint N, minimum, maximum;\nset <unsigned int> result;\nvector <unsigned int> integers;\nbool status = true;\n\nvoid score(unsigned int b, unsigned int step)\n{\n    if(step < N)\n    {\n        unsigned int subtracted;\n        unsigned int added = b + integers[step];\n        bool add_gate = (added <= maximum);\n        bool subtract_gate = (b <= integers[step]);\n        if (subtract_gate) …
Run Code Online (Sandbox Code Playgroud)

c++ recursion

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