重返零点

来源:互联网 发布:火麒麟红包软件 编辑:程序博客网 时间:2024/04/27 15:54

=== 2015-06-04 ===

Using Grep & Regular Expressions to Search for Text Patterns in Linux


=== 2015-04-22 ===

Problems with files with accents in name

For iso 8859-1 accented characters,

set Custom Charset to iso 8859-1  (neither "Autodetect" or "Force UTF-8") then it can download properly to local machine

Safely change primary group of a user in Linux

sudo usermod -g NewPrimaryGroup -G mackey,adm,cdrom,sudo,dip,plugdev,sambashare,lpadmin mackey

chmod

chown

newgrp

chgrp group_name file/directory_name

The difference between Primary and Secondary groups in Linux

[chia]$ id

uid=1000(chia) gid=1000(chia) groups=4(adm),20(dialout),119(admin),1000(chia)

[chia]$ grep  chia /etc/passwd

chia:x:1000:1000:chia,,,:/home/chia:/bin/bash

[chia]$ newgrp admin

[chia]$ id

uid=1000(chia) gid=119(admin) groups=4(adm),20(dialout),119(admin),1000(chia)

GID, current, primary, supplementary, effective and real group IDs?

The first distinction refers to how processes are being run. Normally, when you run a command/program, it is run with the privileges of your user. It has the real group id same as your user's primary group. This can be changed by a process in order to preform some tasks as a member of another special group. To do that, programs use the setgid function that changes their effective group id.

Linux Users and Groups

When set on a file or directory, the sticky bit, or +t mode, means that only the owner (or root) can delete the file, regardless of which users have write access to this file/directory by way of group membership or ownership.

Note, to change the sticky bit, you need to be either root or the file owner.


The setuid bit, or +s, when set on files allows users with permissions to execute a given file the ability to run that file with the permissions of file owner.
Files created in +s directories receive the ownership of that directory’s user and group, rather than the ownership of the user that created the file and their default group.

=== 2015-03-18 ===

C++ 封装,多态,继承特点

=======


stringstream

The basic methods for stringstream are:

  • clear () -- clears the error bits in the stringstream object so that you can use it again. You need to call this each time you start parsing a new string with the stringstream object. If you don't, the object could still be in a bad state and you may not be able to read anything from the stringstream (even if you change its associated string).
  • str () -- returns the string associated with the stringstream object.
  • str (s) -- associates the string s to the stringstream object.
  • operator<< -- add a string to the stringstream object.
  • operator>> -- read something from the stringstream object.

Discover the traps when using stringstream.str()

In fact, when streamstring calls str(), it returns a temporary string object, which will be destructed along with the function return. Thenc_str() is called right afterstr() and the argument passed intoc_str() is a corresponding C string of the temporary string object. Thus, these strings cannot be referenced after the expression evaluation, and the memory will be retrieved or might be overwritten.http://stackoverflow.com/questions/1374468/c-stringstream-string-and-char-conversion-confusion


C++ stringstream, string, and char* conversion confusion

stringstream.str() returns a temporary string object that's destroyed at the end of the full expression. If you get a pointer to a C string from that (stringstream.str().c_str()), it will point to a string which is deleted where the statement ends. That's why your code prints garbage.


As soon as the statement const char* cstr2 = ss.str().c_str(); is complete, the compiler sees no reason to keep the temporary string around, and it's destroyed, and thus yourconst char * is pointing to free'd memory.

0 0
原创粉丝点击