518 Posted Topics
Re: Take a paper, take a pen. Scribble something until it makes sense. Posting without trying is not wise, It just show your ignorance. Although we are here to solve your queries, We, can't work until we have some berries. Those berries are your tries, So, don't post before attempting, it … | |
Re: Well, why are you not using std::strings? I wrote a quick code with those. It is quite flexible: [code=cplusplus]#include <iostream> #include <string> using namespace std; int main() { string input="(98415)4554-215245"; string area,exchange,extention; {//these are added to limit the scope of c_brace & hyphen size_t c_brace=input.find(")");//closing brace size_t hyphen=input.find("-");//the hyphen area=input.substr( … | |
Re: >This helps, but to clarify, instead of taking a string of charecters from a text file and throwing >them into an array, is it possible to take that same concept but do it with binary? Thanks Yes, but don't expect that you would be able to display them. A binary … | |
Re: Why are you not using [URL="http://www.cplusplus.com/reference/stl/vector/pop_back/"]vector::pop_back[/URL] ? [code=cplusplus] do { cout << "Press E to End or Press P to pop a value: "; cin >> selection; if (selection == 'p' || selection == 'P') { cout<<"The integer you popped was: " << values.back();//return last values.pop_back();//delete last } else break; … | |
Re: >I prefer option 2. Same here. But everyone should use option 2 if you are designing a converter, or a filter. It helps other program to use your program's output as their input. | |
Re: Yes. First you need to learn the Basic HTTP protocol. Here([url]http://www.jmarshall.com/easy/http/[/url]) is excellent tutorial for the same. It teaches the protocol by using telnet. Then you should learn about sockets ([url]http://docs.python.org/library/socket.html)[/url]. Also, read the Beej's Network Programming Tutorial ([url]http://beej.us/guide/bgnet/[/url]) it would be helpful, although it is intended for C programmers. … | |
Re: >ONE forward / >or TWO backward \\ Don't advice him to use \\. It will make the code ugly and platform dependent. Always use one forward slash. Learn: [url]http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.7[/url] and [url]http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.16[/url] Anyways, Good Catch | |
Re: [ICODE]int a = ((int-1) * x;[/ICODE] [INDENT]I suppose you meant [ICODE]int a = ((int)-1) * x;[/ICODE] [/INDENT] [ICODE]assert(a == -5);[/ICODE] // Assert fails!!!!! [INDENT]I suppose you meant [ICODE]assert(b == -5);[/ICODE] // Assert fails!!!!![/INDENT] [QUOTE]From TCPL K&R 2nd ed, if either operand of an arithmetic operation is unsigned int, the other … | |
Re: Create a file with all junk upto a maximum size: [code] x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x … | |
Re: >If You Want Something To Do, Try This Exercise... If you are free, try this exercise: Repeat 10 times a day : " Hackers aren't stupid. Programmers are not stupid." And you will magically get the answer. | |
Re: Now this is an interesting case of ignorance. But first, I must give OP the answer: Look at the definition of atoi. It wants a cstring. Which is a null-terminated character array. Tell me, are you giving it a null terminated character array? No you aren't. You are giving him … | |
Re: >>is that the ans of my question? Let me make you one thing clear. This is what Eric. S Raymond said on his article "[URL="http://www.catb.org/~esr/faqs/smart-questions.html"]How to ask question the smart way[/URL]" [QUOTE=Eric Raymond]Never assume you are entitled to an answer. You are not; you aren't, after all, paying for the … | |
Re: >If you are programming in windows, you would use the Windows Application >Programming Interface (WinAPI). And always get struck with windows and make unportable GUIs. Well, there is a very cute library which is called wxWidget. Learn it. It will save you time as it is portable, so would not … | |
Re: >How do you pass a structure array to another class? Same way you pass arrays of integers: [code=cplusplus] using std::cout; struct Points { int xCoordinate; int yCoordinate; int zCoordinate; } point[150]; void display_points(point arr[], int size) { //displays all the points for(int i=0; i<size;++i) cout<<point_arr[i].xCoordinate<<","<< <<point_arr[i].yCoordinate<<","<< <<point_arr[i].zCoordinate<<"\n"; } [/code] | |
Re: >Arw: Click Here What if someone doesn't have a Flash Player. He won't fail LOL. This happened to me while I was viewing it on Lynx(Text based web browser) Anyways. Quite nice link. | |
Re: >>EDIT: ALSO USE CODE-TAGS You can use the noparse tag to tell him that. Use them like this [noparse] [noparse] every thing you write here will not be parsed even the [code] [/code] tags [/noparse][/noparse] | |
Re: [QUOTE=Usura;880881]cool thanx, could you please show me a link to some code? ive pretty new to containers and cant find any examples relating to lists of classes[/QUOTE] [humor] Yeah sure, why not. imthwee is quite good at it. ;) [/humor] | |
Re: Well, you should perhaps try to allocate +1 byte while using new: [icode]char* file_name=new (nothrow) char[str.length()+1];[/icode] You know why!! don't you? | |
Re: For those who suggested the OP: The OP definitely has been given this problem as a homework by his instructor. The instructor wants OP to be able to tell and understand how looping works in programming. Hence, actually running the program would be a sought of 'cheat'. I am sure … | |
Re: [QUOTE]All vibration ceases at Zero Kelvin; All 'things' are made of matter; All matter is made up of particles that vibrate; therefore All 'things' that do not vibrate either Do not exist or exist at Zero Kelvin. [/QUOTE] Wrong!!. You are only considering classical phenomena but quantum mechanics has more … | |
Re: Or perhaps use vectors of [URL="http://www.cplusplus.com/reference/std/utility/pair/"]pair[/URL] of string and double. [code=cplusplus] #include<utility> #include<vector> #include<string> int main() { std::vector<std::pair<std::string,double> > Foo; Foo.push_back( pair("Sally",1021) ); Foo.push_back( pair("John",3.14021) ); std::cout<<"Name:" <<Foo[1].first<<" GPA:"<<Foo[1].second; } [/code] | |
Re: Yes you can. More simply than you can imagine. The only problem is that you shouldn't be playing with the null character '\0'. [code=cplusplus] string answer1 = "anything that has mass and occupies space"; string userresponse1; cout << "1. Define matter.\n"; getline(cin,userresponse1);//<<<<<See the difference if (userresponse1 == answer1) { cout … | |
Re: When you implement .eof(), things doesn't often work they way you think it does. The problem is not in the .eof but in your usage of eof(). Read [URL="http://stackoverflow.com/questions/21647/c-reading-from-text-file-until-eof-repeats-last-line"]this thread[/URL] on Stack Overflow, wherein the OP faces exactly similar problem. The first answer(in green) has brilliant explanation regarding this. | |
Re: Use the [URL="http://www.cppreference.com/wiki/string/substr"]substr[/URL] function to print a subscript. In your case, it will work as: [icode]std::cout<<r.substr(0,2);[/icode] | |
Re: A new-comer should be directed to Python. It is real and it is fun. I have never seen a powerful yet easy language like this. One can almost learn the basic in a weekend. 1.Go to [url]http://python.org/[/url] 2. Download Python for you platform (most GNU/Linux Distros have it pre-installed) 3. … | |
Re: Yes, that line is having the exact problem. change [icode]infile >> songs[counter].bandName = getline(infile, line, ',');[/icode] to [icode]getline(infile, songs[counter].bandName, ',');[/icode] And similarly for each .songName and .duration Why? As your files are comma-separated, there is no point in using the input operator >> . This operator will fetch only a … | |
Re: Your work doesn't impressed me: >How do you open a text file in C++? >What function do you use to store a piece of text from the text file as an array/string. Did you bothered to open your text book or open a search engine and search it? [URL="http://www.catb.org/~esr/faqs/smart-questions.html#rtfm"]RTFM[/URL] and[URL="http://www.catb.org/~esr/faqs/smart-questions.html#rtfm"] … | |
Re: Find your answer by Searching the web: here is a pointer to a good thread which is very near to yours [url]http://groups.google.com/group/comp.lang.c++/browse_thread/thread/1a4b427d09b3eb77[/url] | |
Re: Do the following: 1.Make a new node [I]temp[/I] and store x in temp->info. 2.Set temp->link = here->link 3.Set here->link = temp Thats it As you might have suspected, you don't require [I]first[/I] as an argument, hence the definition of insert should loop like: [icode]void insert(node *here, int x) [/icode] | |
Re: cin >> *h_ptr >> colon >> *m_ptr >> colon >> *s_ptr; This statement is wrong. Tell your user to separate hours, minutes, second by spaces (Like this : "5 15 30") and remove the colon [icode]cin >> *h_ptr >> *m_ptr >> *s_ptr;[/icode] If you want the user to be able … | |
Re: [code]cout << "Are there anymore student grades to enter? (y/n)" <<endl; [COLOR="Red"]{[/COLOR] cin >> inputDone; }[/code] remove the red bracket in your code. | |
Re: >I'm pretty sure everybody is an idiot and most of the time most people don't >know what they're talking about. I don't think so. Most of the time I [I]know[/I] what I am talking about. It is just that very rarely (usually when there is an emotional pressure) I speak … | |
Re: Wow, I really like kid playing with men's tools. So you want to become a cracker? Good Good. Didn't your mother told you that cracking isn't sexy? In my advice, be a hacker. Read : [URL="http://www.catb.org/~esr/faqs/hacker-howto.html"]How to become a Hacker[/URL] | |
Re: short usually 2 bytes, So in your case the 3d array Matrix has size of 2 X 6 X 400 X 400 = 1920000 bytes = 1.83 Mega Bytes. Don't you think it is much? If your program is using this much of memory, ask yourself " Do I really … | |
Re: A little mathematics can do the magic. The sum of consecutive integers from [tex]n_1[/tex] to [tex]n_2[/tex] (including both [tex]n_1[/tex] and [tex]n_2[/tex]) is given by: [tex]sum=n_2(n_2+1)-n_1(n_1-1) \over 2[/tex] (If you need a proof(which is quite trivial), let me know) Hence the problem now remains to run a nested loop with iterators … | |
Re: >It serves the same purpose as endl Not likely. There is a difference between std::endl and \n. (To the OP: The following explanation may not suited for you. The answer of your question was well given in the posts above) To understand lets see what happens you do a cout. … | |
Re: First of all let me simplify your code (and remove unnesasarily added inheritence): So now, have a look at the snippet below [code=cpp] #include<iostream> template<typename T> class tc{};//a template class class Base{};//a base class class Derived : public Base { void der_fct(); /* ... */ };//a derived class int main() … | |
Re: Start with two coordinates. It is trivial that the position of the store in this case would be the mid point of the line joining the two coordinate. Now start with three coordinates. The most suitable location in this case would be a point from which, all the three points … | |
Re: You should perhaps look laws governing the trajectories. I am not going to derive them here (although proof is trivial from Newtons Equation of Motion) but am listing the paramatarized (wrt time) equations governing projectiles. [tex]x=v_0\times cos(\theta) \times t\[/tex] and [tex]y=(v_{0}\times sin(\theta) \times t) - (\frac{1}{2}\times g\times t^2)[/tex] where [tex]v_0[/tex] … | |
Re: Tux, you should also tell him to place the conditional compilation preprocesor directive so that his files are not included more than once: [code] #ifdef MYHEADER_H #define MYHEADER_H //content of the files #endif [/code] This will make sure that this header file will be included only once even if you … | |
Re: I think you should use the [URL="http://cimg.sourceforge.net/"]CImg Library[/URL]. Also note that I found it easily by using a search engine like [url]www.google.com[/url] Always STFW before posting a query. | |
Re: Implementation looks pretty fine. Post the declaration too. BTW, the declaration should be [code=cpp]class student{ public: student(); ~student(); //other stuff }[/code] | |
Re: >>Nope, I can compile it using the newest MinGW compiler Wow! I am fully impressed, I will give you 500 points for this. But, being silent, knowingly that OP is moving toward non-portable code should not be practiced by (a portability fan like) you. The OP should be aware that … | |
Re: As you are, new, I should rather clarify what Narue meant to say. Look at Line 7. That is the declaration of the function (formally this is called a prototype of a function). It tells the compiler "Hey, if you get a call for this function, assume that I am … | |
Re: Everyone who starts using template eventually get struck on this question. Read this for decent answer :[url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.12[/url] If you are still confused (iff only after reading the above link), get back to us. But do read it completely. | |
Re: >>All of a sudden, you could find it happens at some much more obvious and >>inconvenient point in the code (say save file). [QUOTE]Murphy's Law for Computer programming: A program with undefined behavior(or ill defined behavior) will continue to work in all debugging session and will halt when a extremely … | |
Re: >>but problem is how to make this dynamic?? What do you mean by dynamic? BTW, do you realize that the code which you have written is no where near to c++? This is a C code. And you participate in a C++ forum. No doubt you have a red dot … | |
Re: >>From a very good programmer who is both fluent in c and c++ It is a sad part that beginners of the language are actually incapable of telling if a programmer is 'good' or 'bad'. A C guru is not necessarily a C++ guru and vice-versa. Perhaps, a major fraction … | |
Re: You have put the struct student as a private data member. Private members are not inherited. Use the protected specifier to inherit student in the class B. I am still not sure what you exactly want to accomplish. Can you show us by writing a function call in the main(). … ![]() | |
Re: [QUOTE=iamthwee;869143]Alternatively, [code]for ( int i = 0 ; i < v.size(); i++ ) { if ( v[i].name == "Misco" ) { cout << "FOUND\n"; cout << v[i].name << endl; cout << v[i].age << endl; } }[/code][/QUOTE] What a Bull-!@#$ of code was that. Simply lost all purpose of find() To … |
The End.