[Solved] C++ object(int) [closed]

[ad_1] You want to overload << operator. For instance: ostream& operator<<(ostream& os, const Date& dt) { os << dt.mo << “https://stackoverflow.com/” << dt.da << “https://stackoverflow.com/” << dt.yr; return os; } If a() isn’t constructor, but only a () operator overloaded which I assumed changes the a field of the class A to the parameter provided … Read more

[Solved] Advice on how to resolve this error.

[ad_1] A typical linked list structure is made of three parts The Data class Bunny { string name; // don’t use pointers unless you really, really need them int age; bool gender; string color; bool radioactive_bunny; public: string getGender(); // don’t need to know which Bunny anymore because // these functions are bound to a … Read more

[Solved] Determining the Parent Folder of a given Path in C#

[ad_1] You can use Directory.GetParent. .. which returns a DirectoryInfo and you can get the Name or FullName var info = Directory.GetParent(@”directory_path”); var name = info.Name; //this will give parentdirectory var fullName = info.FullName; //this will give pages/parentdirectory [ad_2] solved Determining the Parent Folder of a given Path in C#

[Solved] Build the string dynamically based on the length in c#

[ad_1] Firstly define an extension method for StringBuilder: public static class StringBuilderExtensions { public static void AppendPadded(this StringBuilder builder, string value, int length); { builder.Append($”{value}{new string(‘ ‘, length)}”.Substring(0, length)); } public static void AppendPadded(this StringBuilder builder, int value, int length); { builder.Append($”{new string(‘0’, length)}{value}”.Reverse().ToString().Substring(0, length).Reverse().ToString()); } } Then use: StringBuilder builder = new StringBuilder(); builder.AppendPadded(“Hiwor”, … Read more

[Solved] How to access the object of the class where “=” operator is disabled?

[ad_1] Hmmm Some task… Do one thing create a pointer of that class in your cpp file and assign memory to it using heap allocation. class *myfield = (class*)malloc(no_of_instances*sizeof(class)) Now use that object which is there in your header file assign myfield’s address to that object(hope that is pointer) Now it should work fine.. try … Read more

[Solved] Exception thrown: read access violation. **dynamicArray** was 0x1118235. occurred

[ad_1] There are multiple issues with your program. Let me list all of them one by one. As mentioned in one of the comments, You are immediately deallocating memory just after you allocated it. Definitely this will result in a segmentation fault or memory access violation when you access deallocated memory. When you allocate the … Read more

[Solved] File input output in c

[ad_1] the correct way is: int myreadfile(void) { FILE *fp; int i, n; unsigned char a[50]; if (!(fp=fopen(“x.exe”,”rb”))) return(0); while(n=fread(a,1,sizeof(a), fp)) { for (i=0; i<n; i++) printf(“%02x “,a[i]); printf(“\n”); } fclose(fp); return 1; } Note that the buffer is of type unsigned char. That is because a) you don’t know if the file is a … Read more

[Solved] C++ dynamic way to determine the container to use

[ad_1] You seem to be getting an awful lot of different concepts confused, certainly more than could be sorted out in this form. One way to solve this would be a base class Product from which all your various “product types” derive, solving your first bullet point neatly, as any standard container could hold various … Read more