• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=Darwin226;24863594]Ok, I changed their wrap to ClampToEdge and there are no white lines now but it still gets outlined with them.[/QUOTE] There are no white lines around the edges but there still are?
Probably a dumb question, but how do you get a number value from retrieving a char value. I'm tired so I'm probably not making much sense. [CODE]char num; cin >> num;[/CODE] When I put in the number like 0, it will store the ascII value of 0. What is the way around this?
[QUOTE=Pepin;24870252]Probably a dumb question, but how do you get a number value from retrieving a char value. I'm tired so I'm probably not making much sense. [CODE]char num; cin >> num;[/CODE] When I put in the number like 0, it will store the ascII value of 0. What is the way around this?[/QUOTE] [cpp] int iNum = num-'0'; [/cpp]
[QUOTE=Pepin;24870252]Probably a dumb question, but how do you get a number value from retrieving a char value. I'm tired so I'm probably not making much sense. [CODE]char num; cin >> num;[/CODE] When I put in the number like 0, it will store the ascII value of 0. What is the way around this?[/QUOTE] Add/subtract 48 (0x30)? Also check that it's in the valid number range. 0x30-0x39 before subtraction or 0-9 after.
[QUOTE=ralle105;24870310][cpp] int iNum = num-'0'; [/cpp][/QUOTE] I want to store the variable just in a char, not an int. [editline]09:19PM[/editline] [QUOTE=ROBO_DONUT;24870853]Add/subtract 48 (0x30)? Also check that it's in the valid number range. 0x30-0x39 before subtraction or 0-9 after.[/QUOTE] The issue there is that if I enter any two digit number the stream is going get a bit screwy. I'm in the process of learning C++ and there still is a lot I haven't learned, but I'll get there.
[QUOTE=Pepin;24871596]I want to store the variable just in a char, not an int. [editline]09:19PM[/editline] The issue there is that if I enter any two digit number the stream is going get a bit screwy. I'm in the process of learning C++ and there still is a lot I haven't learned, but I'll get there.[/QUOTE] [Code] Int i; Std::cin >> i; [/code] Maybe? My C++ is a little rusty. Ignore caps. My phone did that.
I know that will work with a variable of type int, but I want to know how to store a number into a char variable using some function. I did this in C a lot using scanf. Well I guess I can use scanf, but if there is some way using cin or something let me know.
A char variable [i]is[/i] just a number. Something like [cpp]char foo = 99;[/cpp] is perfectly valid. It's just the functions that do I/O on chars that handle them differently than other numeric types. Are you trying to read a string of potentially multiple digits, like "99", and store the number ninety-nine in a char variable? For a normal integer type, you'd do this: [cpp] std::string foo = "99"; // or whatever std::stringstream converter; converter << foo; // Like writing to std::cout, but holds the string in memory int value; converter >> value; // Like reading from std::cin, but uses the stored string [/cpp] However, if you change "value" to be of type char instead of int, the >> will read out one character (e.g. '9') rather than the whole numeric value — there's the difference with I/O on chars again. You could make it a function: [cpp] int numeric_value(std::string const &digits) { std::stringstream converter; converter << digits; int value; converter >> value; return value; } [/cpp] Then you can call the function and assign its result to a char variable. (Since the value from the converter is being read into an int variable, it takes the whole numeric value, even if you later assign that result to a char.) Why do you want to store numbers in a char, though?
If I have a variable that isn't going to use more than a 256 values I'd rather store it in a char to save space. Memory space isn't really an issue the computer, but I'm going to start working with some micro-controllers more and it is good to be in the habit of only allocating as much space for a variable as it needs.
On a PC where you don't have to squeeze into as few bytes as possible, it'd be better to use "int". Processors can operate more efficiently on their native word size than on other sizes; an int variable will always be properly aligned for CPU access, but using a char for arithmetic may require unaligned loads, which are slower. You may be interested in reading [url]http://stackoverflow.com/questions/1855222/pros-cons-to-using-char-for-small-integers-in-c[/url]. On a microcontroller, you're more likely to be using C than C++ anyway.
using a short int will take up just one more byte of memory, I don't think you'll be that pressed for RAM. Then again, I have no idea what I'm talking about when it comes to really low level stuff like this. [editline]11:42PM[/editline] oooh according to this: [url]http://en.wikipedia.org/wiki/Integer_%28computer_science%29[/url] C and C++'s [B]uint8_t[/B] and [B]int8_t[/B] use only one byte of memory and have a bound of -128 to 127 if signed or 0 to 256 if unsigned. That should handle math better than a char too!
[QUOTE=robmaister12;24875412]That should handle math better than a char too![/QUOTE] they [i]are[/i] chars [editline]04:58PM[/editline] [QUOTE=jA_cOp;24861453]Boost's range-based loop is done with the for_each templated function or BOOST_FOREACH macro. The syntax he uses is not valid standard C++ and can't be amended by a library like boost. As pointed out, the reason it compiles is because of an MSVC-specific extension.[/QUOTE] Ah, I'd seen people do Boost foreaches and I thought that was what was going on there.
[QUOTE=Wyzard;24869630]There are no white lines around the edges but there still are?[/QUOTE] If I set it to repeat there are white lines on the top and bottom of the quad where there isn't supposed to be anything. When I change it to ClampToEdge I only have white outlines like you can see in the screenshot.
[QUOTE=turb__;24875524]they [i]are[/i] chars [editline]04:58PM[/editline] Ah, I'd seen people do Boost foreaches and I thought that was what was going on there.[/QUOTE] I meant that you wouldn't have to push it through a converter like Wyzard explained. I know it holds the same values, I just thought that having it be an integer-type variable would allow you to work with the number more easily. I've never tried subtracting chars though...
[QUOTE=robmaister12;24875910]I meant that you wouldn't have to push it through a converter like Wyzard explained. I know it holds the same values, I just thought that having it be an integer-type variable would allow you to work with the number more easily. I've never tried subtracting chars though...[/QUOTE] chars are just byte values. They're defined to be one byte. They can be signed or unsigned as well.
How would I go about setting up a threaded socket client in c++? I only need to maintain 1 active outgoing connection at a time. I've googled around but can't find anything obvious.
Reposting because I really need to find a solution. [QUOTE=sim642;24860296]I have such statement : [cpp] if ((Ball2.x >= Pad1.x && Ball1.x <= Pad2.x) && (Ball2.y >= Pad1.y && Ball1.y <= Pad2.y)) { Offset = sf::Vector2f(-Offset.x, Offset.y + (Pads[i].GetPos().y - Position.y)); }[/cpp] Ball1 and Pad1 are top left corners and Ball2 and Pad2 are bottom right corners. This is used for rectangular collision checking, but problem is that I need to somehow find if those 2 rectangles collide on lines parallel to x axis or y axis so I know how should I bounce those. Any advice?[/QUOTE] Rectangle collision isn't hard at all, but how do I know which sides collided : horizontal or vertical?
How do I make a simple auth system? I want to make a simple app that I'm going to sell for $1. I just would prefer if people didn't just copy pasta the app from person to person.
[QUOTE=Agent766;24878598]How do I make a simple auth system? I want to make a simple app that I'm going to sell for $1. I just would prefer if people didn't just copy pasta the app from person to person.[/QUOTE] Ask people to donate rather than selling it? If the app is useful, this will probably get you some money, and paying $1 over the internet feels kinda dumb in my opinion. Anyway, what kind of an auth system do you mean?
[QUOTE=thomasfn;24876574]How would I go about setting up a threaded socket client in c++? I only need to maintain 1 active outgoing connection at a time. I've googled around but can't find anything obvious.[/QUOTE] If you're only going to be handling one connection, it'll be (a whole lot) easier for you to just poll on a non-blocking socket.
[QUOTE=jA_cOp;24879449]If you're only going to be handling one connection, it'll be (a whole lot) easier for you to just poll on a non-blocking socket.[/QUOTE] And with multiple connections, you could just use [url=http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#select]select[/url]. (Or possibly a hacky system with timeouts could work, too. I should experiment with that.)
[QUOTE=esalaka;24879538]And with multiple connections, you could just use [url=http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html#select]select[/url]. (Or possibly a hacky system with timeouts could work, too. I should experiment with that.)[/QUOTE] It's a lot less complicated to do non-blocking sockets (properly) when there's only one socket exactly because of select. Once you've got a threaded connection working for one socket, scaling to more sockets is just a matter of spawning more threads (which isn't a good strategy, but it's simple).
[QUOTE=Agent766;24878598]How do I make a simple auth system? I want to make a simple app that I'm going to sell for $1. I just would prefer if people didn't just copy pasta the app from person to person.[/QUOTE] Nobody is going to go through all the trouble of pirating something they can get for $1. Skip the DRM.
[QUOTE=ROBO_DONUT;24881635]Nobody is going to go through all the trouble of pirating something they can get for $1. Skip the DRM.[/QUOTE] Seen iPhone, what's it called, Crackulous? People go tremendous lengths to not pay $1.
[QUOTE=Wyzard;24875375]...You may be interested in reading [url]http://stackoverflow.com/questions/1855222/pros-cons-to-using-char-for-small-integers-in-c[/url]. On a microcontroller, you're more likely to be using C than C++ anyway.[/QUOTE] Ah, interesting. I was mainly trying to get in the habit of evaluating what data type was needed because my C programming professor told me it was best to get in that habit because it comes in useful when working on large projects.
[QUOTE=arienh4;24883039]Seen iPhone, what's it called, Crackulous? People go tremendous lengths to not pay $1.[/QUOTE] Would those people have paid for your app if they couldn't pirate it? I don't think so. You're not losing any revenue. Don't impose stupid restrictions on legitimate users.
This is either really easy or somewhat difficult, but how would I go about iterating through a directory and adding each file in it into an array of strings, including subdirectories? Something like this: Array[0] = "what.exe" Array[1] = "no.exe" Array[2] = "fuck/asdf.exe" Array[3] = "omfg/stuff.exe" Language is C#.
In System.IO namespace use Directory.GetFiles() and Directory.GetDirectories()
[cpp]string[] files = System.IO.Directories.GetFiles(".");[/cpp] Possibly the overloaded version so specify System.IO.SearchOptions.AllDirectories behavior. [editline]10:49PM[/editline] /me is slow
[QUOTE=ZeekyHBomb;24884657][cpp]string[] files = System.IO.Directories.GetFiles(".");[/cpp] Possibly the overloaded version so specify System.IO.SearchOptions.AllDirectories behavior. [editline]10:49PM[/editline] /me is slow[/QUOTE] Thanks to both of you, I was able to make this ugly function: [cpp] public static List<string> GetJustFilesRecursive(string path) { List<string> result = new List<string>(); foreach (string dir in Directory.GetFiles(path, "*", SearchOption.AllDirectories)) { if (Path.GetFileName(Path.GetDirectoryName(dir)) != Path.GetFileName(path)) { result.Add(Path.GetFileName(Path.GetDirectoryName(dir)) + "\\" + Path.GetFileName(dir)); } else { result.Add(Path.GetFileName(dir)); } } return result; } [/cpp]
Sorry, you need to Log In to post a reply to this thread.