134 Posted Topics
Re: I believe that <string.h> is the old C string header and is now called <cstring> in C++. This is completely different from the C++ strings library. In GCC (g++) you don't need to declare <string> and it will still compile. I guess that it must add it automatically for you, … | |
Re: Vectors can be a lot more convenient to work with than arrays because they're a lot more flexible. For example, you can resize them as you need whereas with an array you'd be giving it a default size when you construct it. If you want to get really good at … | |
Re: You don't "open" c++ in the command line. You edit your programs in a text editor like WordPad/Notepad or in an IDE (much better choice due to syntax highlighting and automatic indentation). Try this IDE if you're just starting out: [URL="http://www.codeblocks.org/"]codeblocks[/URL] Just remember that you'll need to have not just … | |
Re: [QUOTE=greenerworld007;1046006]Hi, I hav heard that it isn't that simple to write a program in linux using c. Lots of commands n stuff.Please simplify what actually I've got to do to run turbo c++ in my linux laptop as I am a beginner.[/QUOTE] It's no harder to write C/C++ code in … | |
Re: You have one of a few choices: 1. Convert your function from returning an int to returning a string 2. Convert MyName to an integer.... maybe something like MyID 3. Convert your function to return a void* and then cast it to a string... Of these choices, option 1 is … | |
Re: [QUOTE=crazyboy;1036570]using len = array.length( ); functionnn[/QUOTE] Correct me if I'm wrong, but length() works for strings not integer arrays. If it does work then please demonstrate how, because I got a syntax error trying it. Here's some code that I know works. It shows 2 ways of getting the length. … | |
Re: "Much to my disappointment, though, my built-in Broadcom wireless network adapter wasn't supported by default." What you're saying is that you had to install the driver. OK... big deal? What I like about Linux is that you can install the Broadcom drivers from the repository. No CDs required. Have you … | |
Re: Do have have access to an admin account? As in any admin account? If so you can reset the password without knowing the old one via net user command. net user administrator * | |
Re: Actually you declared total as in integer and you're using it to store the total price. So, it's not printing any decimals because integers don't have any decimal points in them. | |
My C++ course hasn't covered a topic yet, but I'm expected to solve a few problems with this material. I've got some working code I just don't fully understand it. Can someone help me, please? [CODE] void f(int** a) //What is this ** business? (1) { cout << **a; //prints … | |
Re: If I understand you correctly then you want to remove the spaces in a string in two passes. In one pass you remove the spaces from the left half of the string and then in the second pass you remove the spaces from the right side of the string. The … | |
Re: Who says you can't because my C++ book says you can and my test program works fine too. [CODE] #include <iostream> #include <cstdlib> using namespace std; class MyObject { string data; public: MyObject(string a) : data(a) {} void print() const { cout << data; }; }; int main() { MyObject … | |
Re: For one, i & j aren't declared, unless they are global variables.... but my C++ teacher would kill you for doing that. Take a look yourself: [code] for (i=0;i<3;++i) { for(j=0;j<3;++j) [/code] Should be: for (int i = 0 .....) Also, where is c[][] coming from? It just appears in … | |
Re: [code] #include <sstream> stringstream toString; int num = 55; //Your integer string stringNum; //Your output toString << num; stringNum = toString->str(); toString->str(""); //Clear toString so you can use it again [/code] This code converts an integer into a string. Hope it helps. Here's some more reading on stringstream if you're … | |
Re: [code] cin >> numEntered; //Ask for a number //This part is fine, you get a number from the user numEntered = number[i]; //oops, it's backwards //should be number[i] = numEntered instead [/code] Currently your code says: numEntered is some user input numEntered is some uninitialized data... when you want to … | |
If I have 2 classes a) class Business b) class Customer I want the Business class to be able to store a dynamic list of it's customers. So I thought the easiest way to do this would be to use a vector. [code] class Business { vector<Customer> customers; public: Business(); … | |
Re: According to Bruce Eckel the performance difference between C++ and C is usually less than +/-10%. He also noted that a well designed C++ program can be "more efficient than the C counterpart".... aka it can be faster. In any case we can call them relatively equal... depending on the … | |
Re: I'm lazy so I'll copy and paste from "Beginning Visual C++ 2005" (I have the pdf) When you create a new project workspace, Visual C++ 2005 automatically creates configurations for pro- ducing two versions of your application. One version, called the Debug version, includes information that helps you debug the … | |
Re: I can't think of any really simple way to do this. I suppose you could use something like a struct or a union. This way you could store more than one type of variable depending on what you need. I was thinking something like: [code] #include <iostream> using namespace std; … | |
Re: You said: "Help Me With this please...I'm just learning C++", but you didn't say what you want help with. Where are you stuck? Check for even numbers: variable % 2 == 0 Chick for highest number: just use a variable to store the highest value and use an if statement … | |
Re: iostream allows you to use cout, cin, etc. cstdlib allows you to use system(), exit(), EXIT_SUCCESS, etc. Basically, when you use the #include statement you are adding the ability to use functions/code which were previously written and are located somewhere else in your system, such as in a separate file … | |
Re: Google is your friend. Apparently ncurses is available in Mingw as a user contributed library/package called pdcurses. You can get it.... [URL="http://sourceforge.net/projects/mingw/files/User%20Contributed_%20pdcurses/"]http://sourceforge.net/projects/mingw/files/User%20Contributed_%20pdcurses/[/URL] ...by clicking on the above link. Mind you I've never used this package, but it looks like what you're looking for. Hope it helps. | |
Re: The program is using something called binary shifting. For example: 1 << 1 one is binary "001" shifted by one equals binary 010, aka 2. 1 << 2 Binary 001 shifted by two is binary 100, aka 4. So, if we assume that bin == 100 then our first iteration … | |
Re: [QUOTE=sweetjhin;1010850]I'm not actually looking for a quick answer to my homework. That's why I asked this question because I was hoping that I could find a program that would display the whole calendar. Right now the program I made is just displaying one month and I don't know how to … | |
Re: Why don't you write it out in English and then translate it into C? Just write down what you see in each row, 1 row at a time. If it's row 1 or row 2 then the color is blue .. if it's row 3 and the column is 3 … | |
Re: The way that you do this exercise is you bust out your handy dandy computer, use your problem solving skills to work it out yourself, try to compile the program, and if you still have problems you ask on a forum. You've just posted 3 of your homework assignments with … | |
Re: You do realize that == compares two values whereas = assigns a value. Therefore, it's... t = a; a = b; b = t; | |
Re: I think you need to be a little more specific. What do you want to accomplish? | |
Re: [CODE] while(infile && cnt < a[NROW][NCOL]){ a[cnt][NCOL] = x; ++cnt; infile >> x; }[/CODE] You're while test is wrong. a[NROW][NCOL] has some random value stored in it because it hasn't been initialized yet, same as a it would in a simple one dimensional array. So, what you're saying is "while … | |
Re: Like the others already stated this error comes from trying to manipulate a constant. This should make you wonder a few things including: Why am I trying to manipulate a constant? It totally beats the point of making something constant if you're going to decrement it later. If you have … | |
Re: You'll need 2 for loops (nested). 1 will be for the width and one for the height. [code] for (int column = 1; column < n; column++) { for (int row = 1; row < n; row++){} } [/code] Inside the second for loop (rows) you'll have to implement the … | |
Re: Do you mean like this? [code] string name = "Billy Bob"; cout << "Hello " << name << " you're a wonderful person..." << endl; [/code] | |
Re: Why is main() inside class N??? By the way your code compiles and works on Solaris, but only if main() is removed from the class. Just copy 'n' past MattyRobot's code into your IDE and see for yourself. ;) | |
Re: setw(10) << "Agent's Commission"..... Your problem is in your setw(). Width is set to 10 characters but "Agent's Commission" is like 18 characters..... which beats the point of putting setw(10) in there doesn't it? Set the width so that the output actually fits in the width because right now your … | |
Re: I suppose you could go for a really easy, but inefficient way of sorting by using 2 arrays. One could be your source array and the other would be your destination. Then just keep on looping though your source array. In loop 1 find the smallest number and copy it … | |
Re: The only error in this file is horrible formatting. The program compiles and runs just fine. | |
Re: I find it frustrating when people ask for help and then don't read the help that they've received only to ask the same question over again... When you code an application and it reaches it's end it closes. Meaning the terminal window will close and you will not see your … | |
![]() | Re: There's more than one way to do this. I think that since you don't know how many numbers there are on that line then the easiest way to achieve this would be to use an integer vector and a while loop. While there's data on the line add it to … |
Re: I've used both for a while and I have to say that Win7 is by far the best OS Microsoft has made to date. It's really really nice. It has a lot of really useful improvements in the UI and Win 7 seems to be a lot snappier on the … | |
What's the difference between (aside from syntax I mean): a) typedef struct MyStruct{....}; b) typedef struct{...}MyStruct; I saw this example in "Thinking in C++", but there's no real explanation as to if they're exactly the same or if there's some real difference in them. | |
Re: Correct me if I'm wrong, but wouldn't this be pseudorandom and return the exact same series every time it's run? The way I was taught was to use a seed like this.... #include <ctime> int seed = static_cast<int>(time(0)); srand(seed); int randomNumber = minimum + rand() % (maximum - minimum + … | |
Re: Linux isn't a great platform for gaming. There are few commercial games for Linux so unless you're talking about Flash based games chances are your games won't work. If you want games go Windows. | |
Re: [QUOTE=sknake;951605]Mac/Darwin is a modified FreeBSD, not linux. I hope that helps you some -- I would start looking at BSD options.[/QUOTE] Actually it's a hybrid of the FreeBSD kernel and the Mach microkernel. You're better off getting Mac packages for a Mac. However, if you really need to install Linux/Unix … | |
Re: How big is this array? int marks[student][subject]; Neither student nor subject are not initialized. You initialize them after you create your array. | |
Re: Some software tests your hardware and refuses to install if it's minimum requirements aren't met. Minimum requirements are usually the very minimum required to just barely get the program running. If your computer doesn't meet those then don't bother even trying to play. It won't break your computer, but it … | |
Re: [QUOTE=Anpippin;953954]If I only have Ubuntu on my computer and nothing else does that mean I even have a partition? Because I've never resized the hard drive or partitioned the hard drive or anything like that on that computer.[/QUOTE] Of course you have a partition. You installed Ubuntu into one or … | |
Re: An integer (int) has no decimals. It will never have any decimals no matter what you do with it. Instead of converting to a double start with a double because you will be able to convert doubles to floats (if you so desire), but not the other way around. | |
Re: [QUOTE=neha arora;950099]i wanna know that if a program consists of 10 lines n if we compile it , it shows increased no of lines compiled why:icon_question:[/QUOTE] Because you're not editing your program you're compiling it. The result of a compilation is an executable program (unless there are errors and you … | |
Re: [QUOTE=syedabdulsamad;946469]Hi Can anyone tell me please How i can make program in C++. Thanks.[/QUOTE] I don't think that we can teach you how to program in a forum. However, there is an excellent list of good C++ books/tutorials listed at the beginning of this forum. That would be your best … |
The End.