The Big Programming Thread - Page 38
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
jaydubz
21 Posts
| ||
Pigsquirrel
United States615 Posts
It appears the string is the wrong variable type. What type should I use and is it possible anyway? EDIT Google Came Through:
| ||
fabiano
Brazil4644 Posts
To make it work, use filename.c_str(), since it returns a char* from your object string. | ||
Frigo
Hungary1023 Posts
| ||
![]()
tofucake
Hyrule18968 Posts
Also, you need a semicolon. | ||
EscPlan9
United States2777 Posts
On February 18 2011 01:41 tofucake wrote: It's not a design error. It's just a pain in the ass and you'll run into the problem a lot. Thank god for the c_str() function! I started off programming in Java, so the whole C-style strings vs Strings thing still is weird to me. I'm about to begin my first co-op (basically paid internship). I'm seeking one within software development or system administration (my two concentrations within IT). I have a moderate amount of experience with both Java and C++ (just started learning C++ this quarter but it has been easy to pickup), and very minimal with SQL (mySql only), CSS, and HTML. For those who have done internships, could you go into some detail with some of the work you ended up doing? I'm curious the types of things I should be practicing more on before I'm out programming for a company. | ||
heishe
Germany2284 Posts
On February 18 2011 01:21 Pigsquirrel wrote: I have a C++ question. How would I go about doing something like this:
It appears the string is the wrong variable type. What type should I use and is it possible anyway? EDIT Google Came Through:
Why do you use <iostream> <fstream> and then <string.h> instead of <string> ? | ||
EscPlan9
United States2777 Posts
| ||
IKenshinI
United States132 Posts
On February 19 2011 15:24 EscPlan9 wrote: I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things. Learn C | ||
EscPlan9
United States2777 Posts
| ||
Cloud
Sexico5880 Posts
On February 19 2011 15:24 EscPlan9 wrote: I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things. Maybe you want to shift your learning toward a different direction? Try learning Unix, always a good thing to have in your resume: http://www.catb.org/~esr/faqs/loginataka.html I think Oracle is a bigger standard than MySQL: http://philip.greenspun.com/sql/ I can quote Peter Norvig on "teaching yourself programming in 10 years" Learn at least a half dozen programming languages. Include one language that supports class abstractions (like Java or C++), one that supports functional abstraction (like Lisp or ML), one that supports syntactic abstraction (like Lisp), one that supports declarative specifications (like Prolog or C++ templates), one that supports coroutines (like Icon or Scheme), and one that supports parallelism (like Sisal). Or an interesting blog post by a rather unknown person http://axisofeval.blogspot.com/2011/01/curing-pl-anxiety.html And as ESR says, you're only good when you're recognized as good by other good programmers, and the best way to do that is to work on open source projects. Also possibly the very best thing to have in your resume (awesome if your interviewers can google you!) http://freshmeat.net/ | ||
destian
141 Posts
| ||
Cloud
Sexico5880 Posts
On February 19 2011 15:45 EscPlan9 wrote: I was thinking about C# as one of the next ones I pick up. I read it's sort of like a mix between Java and C++, so should be quick to pickup. Is there a reason I would want to learn C? Does it do something better? It was my understanding that pretty much no company uses C. Rather they want people who know C# and C++ (along with other languages). There is one reason to learn C, and it's more than enough: Unix. Now C is not Unix so you actually have to learn Unix and not only C. | ||
destian
141 Posts
On February 19 2011 15:24 EscPlan9 wrote: I notice a lot of job descriptions ask for a broad range of skills. I'm only good with Java and C++ and know the basics of MySQL, CSS, and HTML. Any suggestions for languages I should learn next? I'm a quick learner especially now that I have a decent "programming mindset" for these things. If you have good experience with those two languages, it really is trivial to learn similar OOP languages. I'd suggest becoming more fluent in SQL. If you're leaning towards a company IT job, learning pivots in SQL will be invaluable. | ||
haduken
Australia8267 Posts
On February 19 2011 15:46 destian wrote: I have a question for anyone who's programming in the MVVM pattern. I'm working on a project that is showing ~30 text fields on a view. I can't help but think there has to be a better way than data binding 30+ properties. This seems wasteful. Any ideas? 30 text fields? Why not just show a grid? | ||
haduken
Australia8267 Posts
| ||
KaiserJohan
Sweden1808 Posts
I can understand there might be different design issues, for example using structs instead of classes. But anything else? Learning unix libraries? :S Also--- would it be wise to use the string class in c++, and then to go through the string use a string iterator? Instead of the traditional way with C strings, I'm wondering which one is the standard in industry: C++ strings or C strings, for C++ programming. For example I can guess c++ string operations will be slower than on C-type strings, but it risk give you buffer overflows or alike. | ||
heishe
Germany2284 Posts
C as a language is syntactically identical to C++. C's grammar (the grammar of its formal language) and it's standard library of course have a lot of stuff missing that C++ has (classes etc., all of the stuff that comes with the STL, also C has no bool ![]() On February 20 2011 02:49 KaiserJohan wrote: For example I can guess c++ string operations will be slower than on C-type strings, but it risk give you buffer overflows or alike. The c++ string class can be accessed like a c-type string without any performance disadvantages:
There should be no performance disadvantages using the [] operator as opposed to using iterators. I'm not entirely sure, since I don't know the implementation of std::string, but the [] operator probably even is faster than iterating through the single chars manually. Why do I think so? Well, internally std::string probably just manages a standard c-type array, which would make it's [] operator implementation as simple as this:
If you'd use iterators, you'd have to iterate through every char manually, which of course would be much much slower. Note that your program will cause undefined behaviour if you try to access something outside the strings range, too, since std::string provides no protection from reading out of range stuff manually. When you iterate through the string using std::string::iterator or const_iterator manually, you can also acces stuff that is out of range by iterating "too far". Nothing saves you from that, as far as I'm aware. As for your question: On February 20 2011 02:49 KaiserJohan wrote: Also--- would it be wise to use the string class in c++, and then to go through the string use a string iterator? Instead of the traditional way with C strings, I'm wondering which one is the standard in industry: C++ strings or C strings, for C++ programming. In your usual application, of course using std::string is standard. It's just much more comfortable to use and provides a lot of functionality that an ordinary c-type char array doesn't have ( string a += "attachment"; for example ) But if you develop something in C++ where performance is really important (especially if you're trying to keep memory usage down) or where you don't need the extra std::string functionality, you might want to consider using standard c-type strings. For example, if you just need the location of a file in a given method, you should consider using
instead of using
since std::string carries a very small (bet still existing) overhead compared to c-style strings in terms of memory usage. filename.c_str() shouldn't be slower than directly handing over a const char *filename, since filename.c_str() should be inlined by your compiler, however, copying a string "into the method" when calling it might actually be slower than copying the pointer to a c-type char array, however I'm not sure about that. | ||
KaiserJohan
Sweden1808 Posts
| ||
EscPlan9
United States2777 Posts
I'll be seeing my professor again tomorrow to help me better understand this. Just curious what any of you would recommend for getting better at it. | ||
| ||