小编use*_*385的帖子

如何将更改提交到新分支

我刚刚对分支进行了更改.我的问题是,如何将更改提交给其他分支?

我正在尝试使用:

git checkout "the commmit to the changed branch" -b "the other branch"
Run Code Online (Sandbox Code Playgroud)

但是,我不认为这是正确的做法,因为在这种情况下我正在创建一个新的分支而不是将更改提交给"另一个分支".

我应该使用以下命令吗?

git merge "the other branch"
Run Code Online (Sandbox Code Playgroud)

谢谢.

git

105
推荐指数
3
解决办法
17万
查看次数

通过char迭代字符串char

我尝试通过char迭代字符串char.我试过这样的事情:

void print(const string& infix)
{
char &exp = infix.c_str();
while(&exp!='\0')
{
         cout<< &exp++ << endl;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以这个函数调用print("hello"); 应该返回:

h
e
l
l
o
Run Code Online (Sandbox Code Playgroud)

我尝试使用我的代码,但它根本不起作用.顺便说一句,参数是引用而不是指针.谢谢

c++

12
推荐指数
3
解决办法
7万
查看次数

Linux sed 命令不改变目标文件

使用我的 shell 脚本,当我运行./Test1 hello result.

它应该hello作为标准输入和结果作为标准输出。外壳应该之前删除任何空白<td></td>abc

所以,我这样写脚本

tr -d [:blank:] < $1
grep -r "<td>" $1 | sed -r 's/<td>//g' > $2
sed -r 's/<\/td>//g' $2
sed -r 's/abc//g' $2
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此命令时,结果文件的内容与 hello 文件的内容完全相同(唯一的区别是删除了空格)

文件你好内容:

<td>hello</td>
  <td>hello</td>
    <td>hello</td>
<td>abc</td>
 <td>abc</td>
Run Code Online (Sandbox Code Playgroud)

如何sed将更改应用到目标文件?

regex linux sed

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

没有operator ==匹配std :: string?

我的程序遇到了一个奇怪的问题.所以在标题中我得到了这样的东西:

#ifndef SET1_INCLUDED
#define SET1_INCLUDED

#include <iostream>
using namespace std;

typedef std::string ItemType;
class Set1{
  public:
  ------some public constructor and method in here-------
  private:
  ItemType setMember[100];
}
Run Code Online (Sandbox Code Playgroud)

在Set1.cpp文件中我的函数的一部分我有这样的东西:

if (setMember[i] == "foo") {exist = true;}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我收到一条错误消息,指出"没有找到哪个运算符,它采用'ItemType'类型的左手操作数".但是,如果我将typedef中的std :: string更改为int或unsigned long,并将"foo"更改为某个随机数,则代码可以正常工作.有什么建议吗?谢谢

c++ string visual-c++

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

在python 2.7.3中完美地工作但在python 3中出错

所以,当我使用命令./randline.py test.txt在python 2.7.3中运行此代码时,此代码工作正常.但是,当我尝试在python 3中运行此代码时,我收到错误消息"/ usr/bin/python:无法打开文件'3':[Errno 2]没有这样的文件或目录"

import random, sys
 from optparse import OptionParser

class randline:
   def __init__(self, filename):
       f = open(filename, 'r')
       self.lines = f.readlines()
       f.close()

   def chooseline(self):
       return random.choice(self.lines)

def main():
   version_msg = "%prog 2.0"
   usage_msg = """%prog [OPTION]... FILE

Output randomly selected lines from FILE."""

   parser = OptionParser(version=version_msg,
                      usage=usage_msg)
   parser.add_option("-n", "--numlines",
                  action="store", dest="numlines", default=1,
                  help="output NUMLINES lines (default 1)")
   options, args = parser.parse_args(sys.argv[1:])

   try:
       numlines = int(options.numlines)
   except:
       parser.error("invalid NUMLINES: {0}".
                    format(options.numlines))
   if numlines < 0:
       parser.error("negative count: …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

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

标签 统计

c++ ×2

git ×1

linux ×1

python ×1

python-3.x ×1

regex ×1

sed ×1

string ×1

visual-c++ ×1