• What Do You Need Help With? V6
    7,544 replies, posted
Any way to create directories and get the number of directories in the current one outside of the system function in C++?
[QUOTE=HumbleTH;46310797]Any way to create directories and get the number of directories in the current one outside of the system function in C++?[/QUOTE] Get familiar with boost::filesystem, its going into the C++ standard soon anyways.
So, I am working on a project and I create an object, which I call std::make_shared on which returns an std::shared_ptr of that object type. I then pass this shared pointer into a container class I wrote, which adds it to an std::vector. So I have an std::vector of std::shared_ptr of my specific object stored inside my container class. Sounds ok right? Well sadly not, turns out if I call functions on the object itself, it works fine for the object, but not the object that the shared pointer inside the vector is pointing to (even though its pointing to that object?) And if I call it on the shared pointer, it calls it on both the object AND the object that the pointer points to! I am very confused, Just thought I would post here to get a bit of frustration out whilst I try to debug this, although any help would be appreciated. EDIT: A few snippets if you want to see (in theory all the problems should be here, although we all know how often that happens) [url]https://gist.github.com/meladath/97b0f87c596a6e7696a5[/url] EDIT: It works just fine using normal pointers...
Is there a reverse-modulo algorithm? For example, if I took current unix time ( 1414098043 ) and put it through modulo 60, and got some number out of the other side, is there a reverse algorithm? in which I know the modulo and I know the Unix timestamp?
Modulo gives you the remainder of division. You'll need to know the quotient as well to get the dividend...
[QUOTE=ThePuska;46314001]Modulo gives you the remainder of division. You'll need to know the quotient as well to get the dividend...[/QUOTE] So if I have 3 terms, a b and c, where a = dividend, b = the divisor, and c = result, and I knew both a and c, is there a way to get b? [editline]23rd October 2014[/editline] Got it: a % b = c or a / b = d remainder c thus (a - c) / d = b
I've got a C# application which I've compiled with Mono. It targets "Any CPU" to tell the JIT to target either 32 bit or 64 bit at run time. It runs fine on my 64 bit Debian server. It uses DllImport to invoke calls to the C Lua library, liblua51.so. The .so is compiled on the server, and sits in the same directory as the C# application. When I recompile the application for my 32 bit Netbook, which also runs Debian, the application runs fine until DllImport is used to access liblua51.so. At this point, the application crashes with the exception DllNotFoundException. [B]What I've tried:[/B] The C# application and liblua51.so have been recompiled on my Netbook liblua51.so has been copied to /lib, /usr/lib, /usr/local/lib (and also still remains in the same directory as the C# application) LD_LIBRARY_PATH and PATH have been modified to look in the current directory (I.E. PATH=$PATH:.) liblua51.so has been renamed/copied to liblua51, liblua51.dll in the same directory as the C# application Any help would be appreciated! Thanks in advance
[QUOTE=paindoc;46314505]I was wondering why it wasn't coloring the "main" bit actually. I can't go to the main definition at all actually. Almost nothing is colored for some reason [t]http://i.imgur.com/h0iZWLo.png[/t] [editline]23rd October 2014[/editline] just did. no dice[/QUOTE] What does your build log say at the bottom of the window when you hit rebuild solution?
[QUOTE=ThePuska;46314550]What does your build log say at the bottom of the window when you hit rebuild solution?[/QUOTE] [code]1>------ Rebuild All started: Project: TutorialProj, Configuration: Debug Win32 ------ ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== [/code] nothin but this [editline]23rd October 2014[/editline] although it was in minimal mode for build output, switched to "normal" [code]1>------ Rebuild All started: Project: TutorialProj, Configuration: Debug Win32 ------ 1>Build started 10/23/2014 3:24:30 PM. 1>_PrepareForClean: 1> Deleting file "Debug\TutorialProj.tlog\TutorialProj.lastbuildstate". 1>InitializeBuildStatus: 1> Creating "Debug\TutorialProj.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified. 1>FinalizeBuildStatus: 1> Deleting file "Debug\TutorialProj.tlog\unsuccessfulbuild". 1> Touching "Debug\TutorialProj.tlog\TutorialProj.lastbuildstate". 1> 1>Build succeeded. 1> 1>Time Elapsed 00:00:00.03 ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========[/code]
[QUOTE=paindoc;46314568][code]1>------ Rebuild All started: Project: TutorialProj, Configuration: Debug Win32 ------ ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== [/code] nothin but this [editline]23rd October 2014[/editline] although it was in minimal mode for build output, switched to "normal" [code]1>------ Rebuild All started: Project: TutorialProj, Configuration: Debug Win32 ------ 1>Build started 10/23/2014 3:24:30 PM. 1>_PrepareForClean: 1> Deleting file "Debug\TutorialProj.tlog\TutorialProj.lastbuildstate". 1>InitializeBuildStatus: 1> Creating "Debug\TutorialProj.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified. 1>FinalizeBuildStatus: 1> Deleting file "Debug\TutorialProj.tlog\unsuccessfulbuild". 1> Touching "Debug\TutorialProj.tlog\TutorialProj.lastbuildstate". 1> 1>Build succeeded. 1> 1>Time Elapsed 00:00:00.03 ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========[/code][/QUOTE] Looks like you have no source code files participating in the build. At least nothing's getting compiled. When you select the files in the "solution explorer", their properties in the "property window" should be approximately: [img]http://i.imgur.com/kga3t8i.png[/img]
does anyone here to haskell? [editline]23rd October 2014[/editline] or lisp? i was thinking of learning haskell because some people recommended it, but i would also learn lisp, because of reasons. [editline]23rd October 2014[/editline] [QUOTE=proboardslol;46307991][code] void input(){ int priceYearOne; int priceYearTwo; scanf("%d",&priceYearOne); scanf("%d",&priceYearTwo); output(calculate(priceYearOne,priceYearTwo)); } int calculate(int priceYearOne, int priceYearTwo){ return (priceYearTwo-priceYearOne)/priceYearOne; } void output(int result){ printf("Inflation Rate is: %d",result); }[/code] is this acceptable by your specification's standards? its in C[/QUOTE] put newlines between functions. the '}' of the current function and '{' of the next function. they should be 2 or 3 lines away for readability.
[QUOTE=ThePuska;46314617]Looks like you have no source code files participating in the build. At least nothing's getting compiled. When you select the files in the "solution explorer", their properties in the "property window" should be approximately: [img]http://i.imgur.com/kga3t8i.png[/img][/QUOTE] this is all I got. And it explains a lot. How do I fix this or add the right files? [t]http://i.imgur.com/wbYBl72.png[/t]
[QUOTE=JerryK;46306377]hey i'm writing a little thing that reads a file for email addresses, identifies them, then writes them to another file i can get all the emails written the output file just fine, but i also need to remove the trailing commas, and only the trailing commas, from the email addresses i'm not really sure how i can do that though so some help would be awesome so far i've got this, written in c++ [CODE] #include <iostream> #include <string> #include <fstream> using namespace std; int main() { ifstream inMails; // Declares the input file ofstream outMails; // Declares the ouput file string email; // Declares the variable for the emails to be written to int at; // Used to identify a string as an email address inMails.open("mail.dat"); // Prepares the input file to be read outMails.open("addresses.dat"); // Prepares the output file to be written // Searches the input file for email addresses then outputs them to // the output file while (!inMails.eof()) { inMails >> email; at = email.find('@'); if (at > 0) outMails << email << endl; } return 0; } [/CODE][/QUOTE] give me some example input and i'll help you out. chances are, just search for the commans and replace them with nothing?
[QUOTE=paindoc;46314728]this is all I got. And it explains a lot. How do I fix this or add the right files? [t]http://i.imgur.com/wbYBl72.png[/t][/QUOTE] Right click on the project -> Add -> New item / Existing item
[QUOTE=ThePuska;46314794]Right click on the project -> Add -> New item / Existing item[/QUOTE] can I just import the classes from a new win32 project?
[QUOTE=Meladath;46311477]So, I am working on a project and I create an object, which I call std::make_shared on which returns an std::shared_ptr of that object type. I then pass this shared pointer into a container class I wrote, which adds it to an std::vector. So I have an std::vector of std::shared_ptr of my specific object stored inside my container class. Sounds ok right? Well sadly not, turns out if I call functions on the object itself, it works fine for the object, but not the object that the shared pointer inside the vector is pointing to (even though its pointing to that object?) And if I call it on the shared pointer, it calls it on both the object AND the object that the pointer points to! I am very confused, Just thought I would post here to get a bit of frustration out whilst I try to debug this, although any help would be appreciated. EDIT: A few snippets if you want to see (in theory all the problems should be here, although we all know how often that happens) [url]https://gist.github.com/meladath/97b0f87c596a6e7696a5[/url] EDIT: It works just fine using normal pointers...[/QUOTE] std::make_shared creates a new object and wraps a std::shared_ptr around it. The function internally calls a constructor and passes all of the parameters to it. These two lines are essentially equivalent: [code]std::shared_ptr<Mesh> box1(new Mesh(box)); std::shared_ptr<Mesh> box2 = std::make_shared<Mesh>(box);[/code] Since the original object is on the stack there is no way to get a shared pointer to it. It wouldn't even make sense because the point of a shared pointer is to automatically call the destructor when there are no more references to the object. An object on the stack will always be destructed at the end of the scope.
-snip, had a breakthrough right after my panic attack...-
[QUOTE=sloppy_joes;46314762]give me some example input and i'll help you out. chances are, just search for the commans and replace them with nothing?[/QUOTE] what i was thinking, is there anyway to stop at the last occurrence of a comma in a string? because sometimes the emails have commas in them example,email@gmail.com, [EMAIL="exampleemail@gmail.com"]exampleemail@gmail.com[/EMAIL], etc.
[QUOTE=JerryK;46315316]what i was thinking, is there anyway to stop at the last occurrence of a comma in a string? because sometimes the emails have commas in them example,email@gmail.com, [EMAIL="exampleemail@gmail.com"]exampleemail@gmail.com[/EMAIL], etc.[/QUOTE] I just pmed you. the code I sent you won't work if there is whitespace after the comma, so you'll have to deal with that.
[QUOTE=Fredo;46314939]std::make_shared creates a new object and wraps a std::shared_ptr around it. The function internally calls a constructor and passes all of the parameters to it. These two lines are essentially equivalent: [code]std::shared_ptr<Mesh> box1(new Mesh(box)); std::shared_ptr<Mesh> box2 = std::make_shared<Mesh>(box);[/code] Since the original object is on the stack there is no way to get a shared pointer to it. It wouldn't even make sense because the point of a shared pointer is to automatically call the destructor when there are no more references to the object. An object on the stack will always be destructed at the end of the scope.[/QUOTE] You should prefer std::make_shared in most cases to avoid an extra allocation. Also, std::make_shared is safer in case of exceptions. [code] fun(std::shared_ptr<mesh> { new mesh { box } }, more_fun()); // May leak if more_fun() throws ... fun(std::make_shared<mesh>(box), more_fun()); // Safe, std::make_shared is a function call ... [/code]
Currently, I am trying to make a twin stick movement system. It works as follows: When the sticks are moved, their vectors combined determine the final direction. This direction is dependent on the direction the camera is facing. When the sticks are pushed in opposite ways of each other, the camera will turn, changing the default position of the character and how the character turns in relationship with the camera. This is how i've tried to do it. [CODE] if (veclen(0,0,joyxpos(),joyypos())>deadzone) joyleft=vec(0,0,joyxpos(),joyypos()); if (veclen(0,0,joyrpos(),joyupos())>deadzone) joyright=vec(0,0,joyrpos(),joyupos()); direction=joyleft-joyright+camdir; [/CODE] The problem is that the behavior is COMPLETELY erratic. I've double checked my controller and even made a vector sidebar to track the stick inputs, and they make sense. What doesn't is the output. also imgur is being an ass so I cant show whats fucking up, so i'll give a shot describing it. When the sticks face the same direction (regardless of direction), the character faces a set direction completely arbitrary from what direction is being pointed. All other behavior is completely unpredictable.
when overriding compareTo in java do you actually have to do .compareTo in the method? I have to compare Strings but I'm not ranking them alphabetically. I have an array of the titles and a method that gets the index then compares the index and uses that comparison in my compareTo method. [code] public class MyClass implements Comparable<MyClass> { String [] titles = {"professor", "teacher", "staff", "student"}; //their ranking is in this order private String title; public MyClass(String title) { this.title = title; } private int compareTitle(MyClass mc) { int comp1 = 0, comp2 = 0; for(int i=0; i<5; i++) { if(this.title.equals(titles[i])) comp1 = i; if(mc.title.equals(titles[i])) comp2 = i; } return comp1 - comp2; } public int compareTo(MyClass mc) { return compareTitle(mc); } } [/code] Would this work for overriding compareTo? edit: I just tested it and it seems to work
[QUOTE=Fredo;46314939]std::make_shared creates a new object and wraps a std::shared_ptr around it. The function internally calls a constructor and passes all of the parameters to it. These two lines are essentially equivalent: [code]std::shared_ptr<Mesh> box1(new Mesh(box)); std::shared_ptr<Mesh> box2 = std::make_shared<Mesh>(box);[/code] Since the original object is on the stack there is no way to get a shared pointer to it. It wouldn't even make sense because the point of a shared pointer is to automatically call the destructor when there are no more references to the object. An object on the stack will always be destructed at the end of the scope.[/QUOTE] Oh right, I was under the assumption it simply wrapped an object! Not created one *facepalm* Thanks, will have to try it using it correctly now :v:
[QUOTE=Trumple;46314138]I've got a C# application which I've compiled with Mono. It targets "Any CPU" to tell the JIT to target either 32 bit or 64 bit at run time. It runs fine on my 64 bit Debian server. It uses DllImport to invoke calls to the C Lua library, liblua51.so. The .so is compiled on the server, and sits in the same directory as the C# application. When I recompile the application for my 32 bit Netbook, which also runs Debian, the application runs fine until DllImport is used to access liblua51.so. At this point, the application crashes with the exception DllNotFoundException. [B]What I've tried:[/B] The C# application and liblua51.so have been recompiled on my Netbook liblua51.so has been copied to /lib, /usr/lib, /usr/local/lib (and also still remains in the same directory as the C# application) LD_LIBRARY_PATH and PATH have been modified to look in the current directory (I.E. PATH=$PATH:.) liblua51.so has been renamed/copied to liblua51, liblua51.dll in the same directory as the C# application Any help would be appreciated! Thanks in advance[/QUOTE] try using an absolute path? thats all i got
[QUOTE=Trumple;46314138]I've got a C# application which I've compiled with Mono. It targets "Any CPU" to tell the JIT to target either 32 bit or 64 bit at run time. It runs fine on my 64 bit Debian server. It uses DllImport to invoke calls to the C Lua library, liblua51.so. The .so is compiled on the server, and sits in the same directory as the C# application. When I recompile the application for my 32 bit Netbook, which also runs Debian, the application runs fine until DllImport is used to access liblua51.so. At this point, the application crashes with the exception DllNotFoundException. [B]What I've tried:[/B] The C# application and liblua51.so have been recompiled on my Netbook liblua51.so has been copied to /lib, /usr/lib, /usr/local/lib (and also still remains in the same directory as the C# application) LD_LIBRARY_PATH and PATH have been modified to look in the current directory (I.E. PATH=$PATH:.) liblua51.so has been renamed/copied to liblua51, liblua51.dll in the same directory as the C# application Any help would be appreciated! Thanks in advance[/QUOTE] Try following these steps to see what mono is trying to load: [url]http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/#troubleshooting-dllnotfoundexceptions[/url]
[QUOTE=Goz3rr;46317924]Try following these steps to see what mono is trying to load: [URL]http://www.mono-project.com/docs/advanced/pinvoke/dllnotfoundexception/#troubleshooting-dllnotfoundexceptions[/URL][/QUOTE] Ah yeah I tried that, it tries to load liblua51, liblua51.so both relatively and with an absolute path to the directory with the application and liblua51.so in [code] root@atom:/home/oli/RSAS/bin# ls -la drwxr-xr-x 4 oli oli 4096 Oct 24 19:29 . drwxr-xr-x 3 oli oli 4096 Oct 23 18:53 .. drwxr-xr-x 2 oli oli 4096 Oct 23 01:08 frameworks -rwxr-xr-x 1 oli oli 189162 Oct 23 22:31 liblua51 -rwxr-xr-x 1 oli oli 189162 Oct 23 22:33 liblua51.dll -rwxr-xr-x 1 oli oli 189162 Oct 23 22:30 liblua5.1.so -rwxr-xr-x 1 oli oli 189162 Oct 23 14:46 liblua51.so -rw-r--r-- 1 oli oli 40448 Oct 23 18:53 Lua4Net.dll -rw-r--r-- 1 oli oli 425472 Oct 23 18:53 Newtonsoft.Json.dll -rw-r--r-- 1 oli oli 28672 Oct 23 18:53 RSAS-common.dll -rw-r--r-- 1 oli oli 12800 Oct 23 18:53 RSAS-server.exe -rw-r--r-- 1 root root 1073 Oct 24 19:29 test.log drwxr-xr-x 3 oli oli 4096 Oct 23 01:08 users root@atom:/home/oli/RSAS/bin# MONO_LOG_LEVEL=debug mono RSAS-server.exe | grep liblua51 Mono: DllImport attempting to load: 'liblua51'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51: cannot dynamically load executable'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51.so'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51.so: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51'. Mono: DllImport error loading library: 'liblua51: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51.so'. Mono: DllImport error loading library: 'liblua51.so: cannot dynamically load executable'. Mono: DllImport loading: 'liblua51'. Mono: DllImport error loading library 'liblua51: cannot dynamically load executable'. Mono: DllImport unable to load library 'liblua51: cannot dynamically load executable'. Mono: DllImport attempting to load: 'liblua51'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51: cannot dynamically load executable'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51.so'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51.so: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51'. Mono: DllImport error loading library: 'liblua51: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51.so'. Mono: DllImport error loading library: 'libl[Error] System.DllNotFoundException: liblua51 Mono: DllImport loading: 'liblua51'. Mono: DllImport error loading library 'liblua51: cannot dynamically load executable'. Mono: DllImport unable to load library 'liblua51: cannot dynamically load executable'. Mono: DllImport attempting to load: 'liblua51'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51: cannot dynamically load executable'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51.so'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51.so: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51'. Mono: DllImport error loading library: 'liblua51: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51.so'. Mono: DllImport error loading library: 'liblua51.so: cannot dynamically load executable'. Mono: DllImport loading: 'liblua51'. Mono: DllImport error loading library 'liblua51: cannot dynamically load executable'. Mono: DllImport unable to load library 'liblua51: cannot dynamically load executable'. Mono: DllImport attempting to load: 'liblua51'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51: cannot dynamically load executable'. Mono: DllImport loading library: '/home/oli/RSAS/bin/liblua51.so'. Mono: DllImport error loading library '/home/oli/RSAS/bin/liblua51.so: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51'. Mono: DllImport error loading library: 'liblua51: cannot dynamically load executable'. Mono: DllImport loading location: 'liblua51.so'. Mono: DllImport error loading library: 'liblua51.so: cannot dynamically load executable'. Mono: DllImport loading: 'liblua51'. Mono: DllImport error loading library 'liblua51: cannot dynamically load executable'. Mono: DllImport unable to load library 'liblua51: cannot dynamically load executable'. [/code] [editline]24th October 2014[/editline] [QUOTE=elevate;46317834]try using an absolute path? thats all i got[/QUOTE] Just tried, no luck but thanks for the suggestions
Does anyone know if there are any good online tutorials for C# around? Im not digging C++'s syntax AT ALL and while the Python tutorials on codecademy seem decent I'd really like to push my existing C# skills more and refine them to a usable level (beyond simple while and for loops in arduino and such)
I've been learning Java independently alongside non-programming college classes, but I've seem a lot of Java hate on /g/ and other places. I know it's verbose compared to other languages, but why exactly does it get so much dislike?
[QUOTE=ArchXeno;46324740]I've been learning Java independently alongside non-programming college classes, but I've seem a lot of Java hate on /g/ and other places. I know it's verbose compared to other languages, but why exactly does it get so much dislike?[/QUOTE] Because it uses shitloads of memory, according to my roommates recent projects
[QUOTE=paindoc;46324750]Because it uses shitloads of memory, according to my roommates recent projects[/QUOTE] It's also generally slower. [URL]http://benchmarksgame.alioth.debian.org/u64q/benchmark.php?test=all&lang=gpp&lang2=java&data=u64q[/URL] I think another reason some linux graybeards dislike Java is its seen as being a lot easier.
Sorry, you need to Log In to post a reply to this thread.