我想知道是否有任何简单的shell命令来更改Linux/Unix中的用户主目录(一个类似于chsh,它改变现有有效用户的默认登录shell)而不触及该/etc/passwd
文件.谢谢
我对下面的模板行为感到困惑,它使用空尖括号(没有参数的模板)编译很好,因为从语法上讲,模板<>被保留以标记显式模板特化.
template <typename T> void add(T a, T b) { }
int main() {
add<>(10, 3); // compiles fine since both parameters are of same data type
add<>(10, 3.2); // Error: no matching function for call to add(int, double)
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中模板参数真的是可选的吗?
#include <vector>
int main() {
struct st { int a; };
std::vector<st> v;
for (std::vector<st>::size_type i = 0; i < v.size(); i++) {
v.operator[](i).a = i + 1; // v[i].a = i+1;
}
}
Run Code Online (Sandbox Code Playgroud)
使用GNU g ++编译器编译时,上面的代码会出现以下错误.
test.cpp: In function ‘int main()’:
test.cpp:6:19: error: template argument for ‘template<class _Alloc> class std::allocator’ uses local type ‘main()::st’
test.cpp:6:19: error: trying to instantiate ‘template<class _Alloc> class std::allocator’
test.cpp:6:19: error: template argument 2 is invalid
test.cpp:6:22: error: invalid type in declaration before ‘;’ token …
Run Code Online (Sandbox Code Playgroud) 如果我运行以下脚本,我收到错误 SP2-0552:未声明绑定变量"OUTRES". 那么,如何定义绑定变量OUTRES以及在何处定义?
#!/usr/bin/bash
sqlplus -s scott/tiger << EOF
declare ret varchar2(10):= '0';
begin
begin
insert into mytab(col1) values(1);
exception
when others then
ret:=ret||'1';
end;
select ret into :OUTRES from dual;
end;
/
quit
EOF
Run Code Online (Sandbox Code Playgroud) 我有这样的文件目标
foo:
i = 1
@echo $(i)
Run Code Online (Sandbox Code Playgroud)
当我像这样运行 make 文件时:
$ make foo
Run Code Online (Sandbox Code Playgroud)
i = 1
make: i: 命令未找到
Makefile:2: 目标 'foo' 的配方失败
make: [foo] 错误 127
但是如果我不给分配空间(即)
i=1
Run Code Online (Sandbox Code Playgroud)
然后没有错误但没有输出,不打印 i 的值
我确实理解将调用各个函数(复制构造函数和赋值运算符)的场景.这两个函数实际上都在执行相同的功能 - 为动态数据成员正确分配内存并从传递的参数对象复制数据,这样对象在数据中看起来都相同.为什么不在这种情况下,C++提供了一个统一的(一个函数),在这两个场景中都会调用它,而不是通过提供两个变体来复杂化?
此Perl代码将输出提供为三.
echo one two three four | perl -pe 's/(\w+)\s(\w+)\s(\w+).*/$3/'
Run Code Online (Sandbox Code Playgroud)
是否有任何优雅的解决方案可以缩短这个冗长的重复正则表达式?
期待了解read -d与IFS变量一起出现时的行为
$ cat f1
a:b:c
d:e:f
$ while IFS= read -d: ; do echo $REPLY; done < f1
a
b
c d
e
$ while IFS=: read; do echo $REPLY; done < f1
a:b:c
d:e:f
Run Code Online (Sandbox Code Playgroud) 我有一个小问题,我还不明白 dbms_output.put_line() 和 dbms_output.put() 之间的区别
set serveroutput on size 200000
Begin
dbms_output.put_line('A' || CHR(10) || 'B');
End;
/
exec dbms_output.put_line('A' || CHR(10) || 'B');
Run Code Online (Sandbox Code Playgroud)
上面给出了两行不同的输出A和B。但
exec dbms_output.put('A')
exec dbms_output.put('B')
exec dbms_output.new_line
Run Code Online (Sandbox Code Playgroud)
不打印任何内容。我正在使用SQL*Plus:版本 11.2.0.1.0 生产
我有以下 C++ 代码,我正在编译如下:
#include <cstddef>
#include <cassert>
template<typename T, std::size_t N> struct A;
template<typename T> struct Base {
T &operator [](std::size_t i);
private:
template<typename T, std::size_t N> friend struct A;
#if !defined(NDEBUG)
size_t n;
#endif
};
template<typename T, std::size_t N> struct A : public Base<T> {
A();
private:
friend class Base<T>;
T a[N];
};
template<typename T, std::size_t N> inline A<T,N>::A() { n = N; }
template<typename T> inline T& Base<T>::operator [](std::size_t i) {
assert(i < n);
return ((A<T,1>*)this)->a[i];
}
int …
Run Code Online (Sandbox Code Playgroud) 如果我注释行插入(s,10),下面的程序编译正常;
#include <iostream>
#include <iterator>
#include <set>
using namespace std;
template <class T>
void insert(std::set<T>& _s, const T& t) {
typename std::set<T>::const_iterator i = _s.insert(t);
}
int main() {
std::set<int> s;
// insert<int>(s, 10); // line No: 14
}
Run Code Online (Sandbox Code Playgroud)
但如果我取消注释第14行,那么我得到的错误是:
set.cpp:9:54: error: conversion from ‘std::pair<std::_Rb_tree_const_iterator<int>, bool>’ to non-scalar type ‘std::set::const_iterator’ requested
我有一个文本文件,其内容如下:
a b
c
Run Code Online (Sandbox Code Playgroud)
我使用下面的Perl代码替换输入行中出现空格char的下划线' - 'char:
while (<>) {
$_ =~ s/\s/_/;
print $_;
}
Run Code Online (Sandbox Code Playgroud)
我得到这样的输出:
a_b
c_
Run Code Online (Sandbox Code Playgroud)
所以我的问题是为什么Perl在换行符'\n'字符处替换下划线,这从包含'c'的输入行中可以看出?当我在代码中使用chomp时,它按预期工作.