casting

Using cin.get to get an integer

我的梦境 提交于 2019-12-29 08:27:10
问题 I want to get a string of numbers one by one, so I'm using a while loop with cin.get() as the function that gets my digits one by one. But cin.get() gets the digits as char s and even though I'm trying to use casting I can't get my variables to contain the numrical value and not the ascii value of the numbers I get as an input. 回答1: cin.get can’t parse numbers. You could do it manually – but why bother re-implementing this function, since it already exists? * int number; std::cin >> number;

problem with printf function?

你。 提交于 2019-12-29 08:11:46
问题 i wrote the following program #include <stdio.h> main() { int i = 2; float c = 4.5; printf("%d\n",c); printf("%f\n",i); return 0; } though i know this is the wrong practice,when i run the program i got the answer as 0 4.500000 but when i exchanged the printf statements a little bit this way #include <stdio.h> main() { int i = 2; float c = 4.5; printf("%f\n",i); printf("%d\n",c); return 0; } the output was 0.000000 0 i couldn't understand whats happening ,any one pls explain me. 回答1: printf

How can I call explicitly implemented interface method from PowerShell?

。_饼干妹妹 提交于 2019-12-29 07:39:07
问题 Code: add-type @" public interface IFoo { void Foo(); } public class Bar : IFoo { void IFoo.Foo() { } } "@ -Language Csharp $bar = New-Object Bar ($bar -as [IFoo]).Foo() # ERROR. Error: Method invocation failed because [Bar] doesn't contain a method named 'Foo'. 回答1: Bad news: It's a bug. https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=249840&SiteID=99 回答2: You can do something like $bar = New-Object Bar [IFoo].GetMethod("Foo").Invoke($bar, @()) You get (the reflection

PostgreSQL ERROR: function to_tsvector(character varying, unknown) does not exist

谁都会走 提交于 2019-12-29 07:05:08
问题 This psql session snippet should be self-explanatory: psql (9.1.7) Type "help" for help. => CREATE TABLE languages(language VARCHAR NOT NULL); CREATE TABLE => INSERT INTO languages VALUES ('english'),('french'),('turkish'); INSERT 0 3 => SELECT language, to_tsvector('english', 'hello world') FROM languages; language| to_tsvector ---------+--------------------- english | 'hello':1 'world':2 french | 'hello':1 'world':2 turkish | 'hello':1 'world':2 (3 rows) => SELECT language, to_tsvector

How to initialize NSString to NSMutableString?

99封情书 提交于 2019-12-29 06:57:50
问题 Is there any way to initialize NSString to NSMutableString? and also reverse order? -(void)st:(NSString *)st { NSMutableString str = st; // gives warning.. NSLog(@"string: %@", str); } 回答1: NSString is an immutable representation (or a readonly view at worst). So you would need to either cast to a NSMutableString if you know it's mutable or make a mutable copy: -(void)st:(NSString *)st { NSMutableString *str = [[st mutableCopy] autorelease]; NSLog(@"string: %@", str); } I autoreleased it

How to cast JObject in JSON.Net to T

两盒软妹~` 提交于 2019-12-29 06:39:21
问题 I know that I can use JsonConvert.DeserializeObject<T>(string) , however, I need to peek into the object's _type (which may not be the first parameter) in order to determine the specific class to cast to. Essentially, what I am wanting to do is something like: //Generic JSON processor for an API Client. function MyBaseType ProcessJson(string jsonText) { var obj = JObject.Parse(jsonText); switch (obj.Property("_type").Value.ToString()) { case "sometype": return obj.RootValue<MyConcreteType>();

Cast a Swift struct to UnsafeMutablePointer<Void>

倖福魔咒の 提交于 2019-12-29 05:16:10
问题 Is there a way to cast a Swift struct's address to a void UnsafeMutablePointer? I tried this without success: struct TheStruct { var a:Int = 0 } var myStruct = TheStruct() var address = UnsafeMutablePointer<Void>(&myStruct) Thanks! EDIT: the context I am actually trying to port to Swift the first example in Learning CoreAudio . This is what I have done until now: func myAQInputCallback(inUserData:UnsafeMutablePointer<Void>, inQueue:AudioQueueRef, inBuffer:AudioQueueBufferRef, inStartTime

How to type cast

拟墨画扇 提交于 2019-12-29 05:14:47
问题 C#: static int F(object x) { return x is string ? 1 : 2; } Haskell? The tricky bit seems to me that Haskell does not have a root type object . Edited: I do not care about converting to string. I want to know how to typecast (for example to see if an object is a Customer or an Order . 回答1: In Haskell, all types that allow a conversion to a string instantiate the Show typeclass which provides show :: Show a => a -> String So your whole code is nothing but f x = show x or f = show with the same

How to type cast

女生的网名这么多〃 提交于 2019-12-29 05:14:33
问题 C#: static int F(object x) { return x is string ? 1 : 2; } Haskell? The tricky bit seems to me that Haskell does not have a root type object . Edited: I do not care about converting to string. I want to know how to typecast (for example to see if an object is a Customer or an Order . 回答1: In Haskell, all types that allow a conversion to a string instantiate the Show typeclass which provides show :: Show a => a -> String So your whole code is nothing but f x = show x or f = show with the same

When is an integer<->pointer cast actually correct?

狂风中的少年 提交于 2019-12-29 03:11:38
问题 The common folklore says that: The type system exists for a reason. Integers and pointers are distinct types, casting between them is a malpractice in the majority of cases, may indicate a design error and should be avoided. Even when such a cast is performed, no assumptions shall be made about the size of integers and pointers (casting void* to int is the simplest way to make the code fail on x64), and instead of int one should use intptr_t or uintptr_t from stdint.h . Knowing that, when is