Questions tagged [c++]

596530 questions
1

votes
3

answer
112

Views

Cannot create simple class

I am trying to create a very simple CUser class in my project, but apparently I am doing something wrong. Here is the code: using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Web; using MySql.Data.MySqlClient; namespace admin.NET.lib { public cl...
Interfector
1

votes
5

answer
213

Views

What is the best way to resolve an object?

I've written a resolver so I can have a very primitive DI framework. In the framework I allow for a dependency resolver to specify what default types to load if nothing is specified or registered. However, the way I do the default loading has got me wondering. I'm not sure I'm doing it the best wa...
Joseph
1

votes
4

answer
1.7k

Views

How can I create a zip file using C#? [duplicate]

Possible Duplicate: .Net Zip Up files I want to zip a .csv file using C#. How I can do this?
CRK
4

votes
2

answer
346

Views

How to effectively validate an integer that represents a flagged enumeration?

Consider FileAttributes enumeration which is designed for bitwise operations. I've created a system in which, user selects some checkboxes to determine the status of a file. A file may be both ReadOnly and System. Thus the value would be 5 (1 for ReadOnly and 4 four System). How can I validate an in...
Saeed Neamati
3

votes
2

answer
3.1k

Views

c# how to change the tray icon

I'm still learning C# and I'm stuck. My problem is that I have a tray icon, which has to be changed when somthing happens. I have added the new icon as an existing item to the project and I'm trying to change it by using this code: this.notifyIcon1.Icon = new Icon(GetType(), "newmailIcon.ico"); But...
Code Beast
1

votes
5

answer
63

Views

Regular Expression for a project Number help

I am in need of some regular expression help. (regex is not my strong point!) I have to iterate through a spreadsheet and match the strings that look like this: AZP2006-056.03 ABC####-###.## so first three can be any letter, four digit year and a 3 digit number with a two decimal place value. Can so...
adminJaxon
3

votes
2

answer
106

Views

Selenium is telling me the ID doesn't exist

When I run the following program it runs absolutely fine, until I get to filling out the form on the webclip section. Once it gets there it says the id "txtTemplateName" can't be found. I copied and pasted that name directly from Inspecting the element. It isn't that i'm not giving it enough time to...
Evan
15

votes
3

answer
24.9k

Views

Convert UTC DateTime to DateTimeOffset

I need to convert UTC date strings to DateTimeOffsets. This must work with a timezone which differs from the computers timezone. E.g. current computer timezone is +02:00, but I want to create a DateTimeOffset with offset -4:00. I already read lot of questions here on stackoverflow, but none of them...
Fabian
2

votes
2

answer
38

Views

How can I check my special enum's value in a customized control has changed in C#

I created a custom control class which inherits from Button class. The reason I did that is I need to create the same button and I don't want to do everything every single time. And I want a drop down list for the properties that I add on the visual studio properties tab. For example, I want three d...
HeroOfSkies
2

votes
1

answer
56

Views

C# Displaying total amount of money in a class instance

I'm taking an online c# class and it asked me to fill in some of the blanks and I figured out everything expects this: In my console app I added up a different amount of money and now I'm trying to display them. My end result should look like this: My code: namespace CashRegister { class Program { s...
Samurai
1

votes
4

answer
240

Views

Converting date to string for logfile, and then from string to DateTime for Database

If I save the date and time in this format: string sLogTime = "MMM ddd d HH:mm yyyy"; ...what will I then have to do to convert that string into a recognizable value for a SQL Server DateTime column? Something like so: DateTime dtLogTime = Convert.ToDateTime(sLogTime); . . . cmd.Parameters.Add(...
B. Clay Shannon
15

votes
3

answer
9k

Views

ASP.NET MVC Controller Unit Testing - Problem with UrlHelper Extension

Trying to do some controller unit-testing in my ASP.NET MVC 3 web application. My test goes like this: [TestMethod] public void Ensure_CreateReviewHttpPostAction_RedirectsAppropriately() { // Arrange. var newReview = CreateMockReview(); // Act. var result = _controller.Create(newReview) as RedirectR...
RPM1984
1

votes
5

answer
678

Views

How to copy between generic declared types with value type constraints

I have a generic method that copies values between value types. The following approaches give a design time error, even with the struct constraint. Any idea how I can copy or cast between the values? private Ttgt MyMethod(Tsrc SourceObject) where Tsrc : struct where Ttgt : struct { //Error:cannot i...
Jon Simpson
2

votes
4

answer
1k

Views

What is a good commercial tar stream lib for c# and .net?

We are currently using SharpZipLib but since it uses the GPL we need to replace it with a commercial lib.
Erin
1

votes
3

answer
212

Views

How to strip leading “http://” from char array in C?

I have a function (in C) that is passed a URL. This function only works if the URL parameter is in the form of www.example.com, not when it is http://www.example.com. I would like to modify this function so that, when passed a URL in the form of http://www.example.com, it strips the leading http://...
rps
2

votes
3

answer
116

Views

Using a pointer variable typedef

I define a typedef typedef char* charP; Then I declare a few variables charP dog, cat, fish; Are all the variables of type char* or is dog the only char* while cat and fish are of type char?
user3812169
5

votes
1

answer
218

Views

C++ Why use an implicit conversion from (std::string) to (void) type?

I'm looking at CPP-NETLIB's source code and came across this syntax where it describes the concepts. template struct ClientRequest : network::Message { BOOST_CONCEPT_USAGE(ClientRequest) { std::string tmp; R request_(tmp); swap(request, request_); // swappable via ADL std::string host_ = host(requ...
etcimon
1

votes
4

answer
190

Views

ternary and assignment operator precedence

On MSVC v9.0, if I do this: int myvalue; myvalue = true ? 1 : 0; then it seems that ?: is evaluated before '='. Is this a guarantee? I am using this table as a reference: http://en.cppreference.com/w/cpp/language/operator_precedence However, both operators are in the same row, so I'm not sure if the...
void.pointer
1

votes
2

answer
349

Views

System Wide persistent storage?

My program starts a process and I need to make sure it is killed before I can run the program again. To do this, I'd like to store the start time of the Process in something like a mutex that I could later retrieve and check to see if any process has a matching name and start time. How could I do th...
Malfist
1

votes
2

answer
189

Views

calling resize on std vector of pointers crashed

The problem can be reproduced using VS 2013 Express. It crashed when internal vector implementation tried to deallocate the original vector. However, the problem can solved by using 'new' instead of 'malloc'. Anyone can shed some light on this? struct UndirectedGraphNode { int label; vector neighbo...
user11869
4

votes
1

answer
295

Views

c# - inherit two classes from one base class gives error 3024

I have three tables in my database t1, t2 and t3 and t1 is "base" of t2 and t3. Each table has a column named Id and t2 and t3 has also a column named t1Id. There are also ForeignKey-Constraints on t1.t1Id and t2.t1Id / t3.t1Id with cardinality 1 to 0..1. In VisualStudio EF-Modeldesigner I generate...
amens
1

votes
2

answer
402

Views

Trouble with relationships in Entity Framework

I have a trouble with relationship in EF v4.I know that this question very popular, I tried to find something in Internet, but it didn't help. I have class Person that has one-to-one with Address(Person has Address) class Person { public int PersonId{get;set;} public string FisrtName{get; set;} ......
BeginerDummy
1

votes
5

answer
379

Views

Format String : Parsing

I have a parsing question. I have a paragraph which has instances of :  word  . So basically it has a colon, two spaces, a word (could be anything), then two more spaces. So when I have those instances I want to convert the string so I have A new line character after : and the word. Removed t...
MindGame
2

votes
2

answer
61

Views

In a ControlTemplate, I want to apply the same style to all TextBlocks

I have a class library, in which I've created default styles for TextBlock, which is applied to every TextBlock in any application that uses this class library. The problem is that I sometimes need to exclude TextBlocks inside some other controls (say, ribbon, or my own Custom Control). The textbloc...
Alireza
2

votes
2

answer
1.4k

Views

Hosting a WebService/WCF on Windows Mobile Device?

I'm interessted in writing an application that is running on windows mobile. I've allready a winform application that is hosting an WCF service. I wan't to port the application to windows mobile (6.0) and up. MSDN is hosting an article about WCF on Compact Framework, but it says hosting is not an op...
Marco Scheel
3

votes
1

answer
1.1k

Views

Need UrlHelper inside global.asax

I need to set up a bunch of paths and URLs when my app starts, ie in global.asax. Using UrlHelper.Content() is the easiest way to do that, but it is not available for use. So how can I get an instance of it inside global.asax? I tried creating one, but of course RequestContext doesn't exist. The ans...
merom4
3

votes
2

answer
154

Views

C# - passing SomeClass to a function instead of typeof(SomeClass)

I've implemented an ActionFilterAttribute which maps SomeClass to SomeOtherClass. Here's the constructor: public class MapToAttribute : ActionFilterAttribute { private Type _typeFrom; private Type _typeTo; public int Position { get; set; } public MapToAttribute(Type typeFrom, Type typeTo, int Positi...
vzwick
2

votes
1

answer
1.1k

Views

C# Expression Trees - Dynamic Value Lookup

I'm building a C# expression tree to evaluate simple expressions. The expression strings are parsed into trees, and respect the basic operators (mathematical, logical and relational) as well as precedence through the use of parantheses. In addition to the types bool, string and integer - I require s...
fturtle
3

votes
1

answer
29

Views

Angular JS Application Is Failed with Multi Post Request

I am consuming a WCF service from an AngularJs application. I am posting multiple requests to the service. With this request I am checking the user information. This is the service that is throwing the error: public bool cheekCreditScore(Credit_Crad credit) { int i = 600; int j = 700; SqlConnection...
Mohammad
2

votes
1

answer
37

Views

Angular web application Databinding is not working

I am consuming wcf rest service into angular js application. I am trying to display single record in angular js application based on Account Holder Last Name and parameters type is string . The method types is GET .when the post the value to wcf service and its receive the values .Its check the valu...
Mohammad
4

votes
4

answer
356

Views

Speeding up ASP MVC Unit Tests

How do people run their automated tests for ASP MVC ? Currently we're using native Visual Studio unit tests and running them linearly on a single machine. They're too slow to be useful currently. Switching to nunit? Distributing the unit tests with Incredibuild XGE? Anyone tried these or have other...
Christopher Stott
3

votes
1

answer
159

Views

What is a 'thunk'? (in the context of re-entrant sort functions, eg: qsort_r)

Having already checked What is a 'thunk'?, I'm still not sure why the extra argument passed to the re-entrant qsort_r would be called thunk. Eg: (BSD style qsort_r) void qsort_r(void *base_, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *)); To be clear, I kn...
ideasman42
3

votes
3

answer
531

Views

merge in-place without external storage

I want to merge two arrays with sorted values into one. Since both source arrays are stored as succeeding parts of a large array, I wonder, if you know a way to merge them into the large storage. Meaning inplace merge. All methods I found, need some external storage. They often require sqrt(n) temp...
Anastasia Rushda
15

votes
6

answer
836

Views

Have you ever seen design with reasonable usage of protected internal access modifier?

I haven't, but I don't say there isn't one. All of the C# developers who read this probably do know what is protected internal and when to use it. My question is simple : did you actually ever use it or worked on a successfully designed project using protected internal access modifier? If yes, pleas...
Xorty
1

votes
8

answer
124

Views

Find string with most frequency of a character in List of strings using LINQ C#

I am dealing with binary vectors so each string in a List looks like vectors[0] = "1 0 0 0 1 1 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1"; vectors[1] = "1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1"; I want to get the biggest string from the List, with most number of 1's.
3

votes
1

answer
57

Views

Aibohphobia SPOJ

I am trying to solve this exercise. I have a solution, as below, but I am getting Time Limit Exceeded error. I want to learn why this code is inefficient since I am doing memoization. namespace Aibohphobia { class Test { static Dictionary memo = new Dictionary(); static int Main(string[] args) { st...
Suresh Iyengar
3

votes
3

answer
120

Views

implementing operator * in C++

class Rational { const Rational operator*(const Rational& rhs) const ... }; Rational oneHalf(1,2); Rational result = oneHalf * 2; // fine (with non-explicit ctor) result = 2 * oneHalf; // error! (even with non-explicit ctor) It was mentioned by scott meyers in Effective C++ book as below...
venkysmarty
4

votes
2

answer
167

Views

Pointer in structure memory allocation in initialization (c99)

Lets assume that we've got a type: typedef struct __BUFF_T__ { u_int8_t *buf; u_int32_t size; }buff_t; Is it correct allocating memory next way in c99? buff_t a = {.size = 20,.buf = calloc(a.size,1)}; Compiler shows warning Variable 'data' is uninitialized when used within its own initialization Mem...
Artem Gulyamshaev
2

votes
4

answer
1.3k

Views

WCF Contracts without the annotations [duplicate]

This question already has an answer here: Is DataContract attributes required for WCF 4 answers I was wondering if there is any way to define a WCF Contract class without using the [DataContract] and [DataMember] annotation. The reason is that domain model we currently have is fairly clean so we wo...
Yannis
3

votes
1

answer
704

Views

Custom ScrollBar styling artifact?

What is this rectangle and how to get rid of it? I am only templating scrollbars: I doubt if it's a ScrollBar, more like ListBox itself. The problem only appears when horizontal scrollbar is visible. To example, here guy templating ScrollViewer and as you can see image is without artefact or interse...
Sinatr