tilde

tilde operator returning -1, -2 instead of 0, 1 respectively

江枫思渺然 提交于 2019-12-01 18:41:49
I'm kind of puzzled by this. I thought the ~ operator in C++ was supposed to work differently (not so Matlab-y). Here's a minimum working example: #include <iostream> using namespace std; int main(int argc, char **argv) { bool banana = true; bool peach = false; cout << banana << ~banana << endl; cout << peach << ~peach << endl; } And here's my output: 1-2 0-1 I hope someone will have some insight into this. This is exactly what should happen: when you invert the binary representation of zero, you get negative one; when you invert binary representation of one, you get negative two in two's

Echoing a tilde to a file without expanding it in Bash

萝らか妹 提交于 2019-12-01 16:41:56
I need to write an argument to a file in a Bash script, so I'm doing something like this, echo "Argument is: $1" >> file The problem is that if there's a tilde (~) in the argument I don't want it expanded to the home directory. So if the user passed ~/bin as an argument to the script, it would get written as ~/bin and not /home/user/bin. How do I do this? I assume your program is started as: $ your_prog ~/foo The argument is translated before your program is even started, so there's nothing you can do to prevent it other than educating the user to quote appropriately if the expansion is not

Qt: Expand ~ to home-directory

牧云@^-^@ 提交于 2019-12-01 16:33:41
Does Qt have any platform-independent functionality to accept paths like "~/myfile"? I know about wordexp , but it would be nice with a platform-independent wrapper. Edit: Thank you all for the responses. "~/myfile" was just an example. What I am looking for is functionality to handle file-paths as you would be able to write on the command-line. So on Linux, it should accept "~/myfile", "~otheruser/hisfile", "$VAR/file" etc. On Windows, it should accept "%HOMEDIR%\myfile" etc. ChristopheD You could probably just replace the tilde with the result of QDir::homePath() ? Reference here . Klathzazt

Qt: Expand ~ to home-directory

心已入冬 提交于 2019-12-01 15:17:54
问题 Does Qt have any platform-independent functionality to accept paths like "~/myfile"? I know about wordexp, but it would be nice with a platform-independent wrapper. Edit: Thank you all for the responses. "~/myfile" was just an example. What I am looking for is functionality to handle file-paths as you would be able to write on the command-line. So on Linux, it should accept "~/myfile", "~otheruser/hisfile", "$VAR/file" etc. On Windows, it should accept "%HOMEDIR%\myfile" etc. 回答1: You could

C++ paths beginning with ~ [duplicate]

南楼画角 提交于 2019-12-01 04:12:21
问题 This question already has an answer here : mkdir fails with tilde on OS X in C? (1 answer) Closed 4 years ago . Is here any possibility to use paths beginning with "~" in c++ codes in linux? For example this code is not working correctly: #include <iostream> #include <fstream> using namespace std; int main () { ofstream myfile; myfile.open ("~/example.txt"); myfile << "Text in file .\n"; myfile.close(); return 0; } 回答1: I guess you are on a Linux or POSIX system, with an interactive shell

Tilde-based Paths in Objective-C

僤鯓⒐⒋嵵緔 提交于 2019-11-30 23:05:31
In Objective-C, how do I go about converting tilde-based pathnames to full pathnames? That is, I'd like to convert from ~/sandbox to /Users/TheBobs/sandbox . Ben S Use NSString's stringByExpandingTildeInPath: method. There are also several other methods that make it easy to work with paths . 来源: https://stackoverflow.com/questions/1675852/tilde-based-paths-in-objective-c

Tilde-based Paths in Objective-C

倖福魔咒の 提交于 2019-11-30 17:50:58
问题 In Objective-C, how do I go about converting tilde-based pathnames to full pathnames? That is, I'd like to convert from ~/sandbox to /Users/TheBobs/sandbox . 回答1: Use NSString's stringByExpandingTildeInPath: method. There are also several other methods that make it easy to work with paths. 来源: https://stackoverflow.com/questions/1675852/tilde-based-paths-in-objective-c

Using tilde in script tag src attribute

天涯浪子 提交于 2019-11-30 17:20:50
In my asp.net website using MasterPage and Routing I use a tilde in the href attribute of the link tag for the stylesheet in the head section of the MasterPage. Like this: <link href="~/Styles/Main.css" rel="stylesheet" type="text/css" /> Which works like a charm. Since the website uses routing the url will contain more and more / , yet the stylesheet's href remains valid because the tilde points to the root of the web application and the styles are used. I tried using the same technique for the src attribute of the script tags, but this doesn't seem to produce the expected result. I tried:

Using tilde in script tag src attribute

↘锁芯ラ 提交于 2019-11-30 16:36:57
问题 In my asp.net website using MasterPage and Routing I use a tilde in the href attribute of the link tag for the stylesheet in the head section of the MasterPage. Like this: <link href="~/Styles/Main.css" rel="stylesheet" type="text/css" /> Which works like a charm. Since the website uses routing the url will contain more and more / , yet the stylesheet's href remains valid because the tilde points to the root of the web application and the styles are used. I tried using the same technique for

What's the function of the ~ bitwise operator (Tilde) [duplicate]

梦想的初衷 提交于 2019-11-29 13:23:38
Possible Duplicate: What does this ~ operator mean here? Bit not operation in PHP(or any other language probably) Can someone explain me the ~ operator in PHP? I know it's a NOT-operator , but why does PHP convert following statement to the negative value of the variable minus one? $a = 1; echo ~$a // echo -2 $a = 2; echo ~$a // echo -3 $a = 3; echo ~$a // echo -4 This is called the two's complement arithmetic . You can read about it in more detail here . The operator ~ is a binary negation operator (as opposed to boolean negation), and being that, it inverses all the bits of its operand. The