Lucky you with your snow.
I have a blistering sun...
damn! haven't seen snow in 17 years now...
Must be somewhat boring to have only one season -- hot!
Lucky you with your snow.
I have a blistering sun...
damn! haven't seen snow in 17 years now...
Must be somewhat boring to have only one season -- hot!
>>sort(phone[1].begin(), phone[1].end());
try this: sort(phone.begin(), phone.end());
And you will have to supply a comparison function because sort() doesn't know how to compare structures and classes.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct Entry
{
int array[10];
};
bool compare(Entry& e1, Entry& e2)
{
// compare the two structures
return e1.array[0] < e2.array[0];
}
int main()
{
vector<Entry> phone(1000);
sort(phone.begin(), phone.end(), compare );
}
what is a firewire? do you mean firewall?
[edit] Oh nevermind, I should take my own advice and google what I don't know [/edit]
Try reading the Read Me threads at the beginning of this board. And stop using all caps because its considered very rude to shout at us.
>>and it still showed quite some errors
Can't help you if you don't post the exact error message(s)
std::sort only works with arrays such as a vector. If you want to use a structure then great, but you need an array of structures.
First snow of the winter for us, but we only have about 1 inch. :) I like to see a white Christmas, but don't like the suff at other times because its such a pain to remove from sidewalks, roads etc. I know most of you young people have lots of fun in it, so I hope you get to enjoy it a lot this winter.
I'll take a couple of these:
Damien Hirst’s sculpture, titled “For The Love of God”. It represents a platinum skull encrusted with 8,601 diamonds, eye and nose sockets filled with hundreds of jewels and a 52-carat pear-shaped stone fixed on the forehead, which is further bordered with 14 diamonds. It was influenced by Mexican skulls encrusted in turquoise. The skull has been sold to an investment group for $100 million.
Probably referring to this post which just seems to be very similar. But got to admit that stevex is pretty darned long winded :)
line 1: >>INPUT_RECORD fillBuff(std::string value) {
That should be returning a pointer, not a single element of an array
line 42 of main(): >> records = &fillBuff(value);
and that probably doesn't really work the way you think it does either.
line 23: >> return irec[0];
You can't return an object that was created on the stack and is probably why the program is getting junk. Several ways to resolve the problem. And that does not return a pointer.
1) make irec a static array static INPUT_RECORD irec[10];
. Then on line 23 should be this: return irec
which will return a pointer to the first element of the array.
2) pass irec as a parameter INPUT_RECORD fillBuff(std::string value, INPUT_RECORD* irec) {
3) declare irec as a pointer inside fillBuff() and allocate it with new
I don't want anything made in China!
Oops! I missed the part about 2008 vs 2005. Guess I need new reading glasses :)
>>project for my 12th boards
we don't know what you mean by that.
>>program using BINARY FILES
Don't know exactly what you mean by that either. Do you want the vehicle data to be written to and read from a data file in binary format? You need to create an array (or c++ vector) of vehicle classes vector<vehicle> vehicleArray;
then when done inputting the data write them all out to a file in their binary form
ofstream out("vehicles.dat", ios::binary);
vector<vehicle>::iterator it;
for(it = vehicleArray.begin(); it != vehicleArray.end(); it++)
{
vehicle& v = *it;
out.write(&v, sizeof(vehicle));
}
Reading the file on program startup is just as simple. Leave that up to you to write.
My age group would consider it total crap. But that's what my parents thought about our music too :)
my guess is they are only supported on *nix and POSIX. Microsoft compilers have very little POSIX support. Even GNU doesn't seem to support it across all platforms of its compilers. I have the most recent version of Dev-C++ and monetary.h is not supported there either.
I think you would get quicker and probably better advice from Oracle's forum boards that specialize in Pro*C SQL language.
From what I understand all versions use the same compiler and IDE -- the difference between versions is the add-ons that are packaged with it. I know that the Pro version is equipped with MFC and cross compilers for various embedded Mobile 5.0 operating systems. But its highly unlikely first year students will need either of those features.
I just compiled it ok, but I put printAllStrings() at the top of the file before main()
Welcome to DaniWeb Peeta. You can use almost any compiler that is targeted for your operating system. For example you can not use a compiler for MS-Windows on a MAC and vice versa. Here is one place to look for free compilers. Try to make google one of your best friends because it can often find the information you want very quickly.
DLLs are much like normal static libraries. Create a header file with the dll functions you have exported and include it in your console project, then add the .lib file that the compiler created for the dll in the console project just like you would any other project.
I use a conditional compile preprocessor directives in the header file so that it can be included in both the dll build and the console application build
// header file
#if defined(DLL_BUILD)
#define MYAPI __dllexport
#else
#define MYAPI __dllimport
#endif
void MYAPI foo(std::string& datastr);
why don't you just use getline() to input the sentence instead of that more complicated use of get().
cin.getline(sentence,sizeof(sentence));
letters = strlen(sentence);
Now you will probably have to use a structure of letter number and frequency so that you can sort the structures by frequency while maintaining the relationship with its letter value
struct frequency
{
char letter;
int count;
};
vector<frequency> counters;
At this point you have to iterate through sentence, search counters array for the current letter. If not found then add one to the array otherwise if found just increment the count for that letter.
Here is how to sort a vector
If you use static the value of i will be the same for all instances of the class and there will be no way to reset it back to 0 if you need to. I think a better solution is to use a different variable name and make it a class object so that each instance of the class has its own variable and you can reset it to 0 whenever you need to.
No you can use the CString object directly
CString str = _TEXT("Hello World");
AfxMessageBox(str,MB_OK);
or
CString str = _TEXT("Hello World");
MessageBox(str.GetBuffer(),"Debug Message",MB_OK);
Or if you know how long it takes for the music to play then you sould just call Sleep() for that many milliseconds.
Actually it doesn't really matter about that error because cout can not print to any MFC (or non-MFC) window. The output is just tossed into the bit bucket by the os. If you want to see debug messages then use MessageBox().
Are you certain you are talking about line 21? It would seem more reasonable that line 16 should give you that error because ss is a CString object and cout doesn't know out to output it, or CString doesn't have an << operator for cout unless of course you wrote it yourself.
did you include <string> at the top of your program?
[search]how to clear the screen[/search]
And besides, don't the foolish deserve representation in the government as well?
They already are representated -- most politicians are very foolish and squander our hard-earned tax dollars. Like that highway in Alaska that went to nowhere.
how to make certain that the person casting the vote is really the person he says she is.
Are you saying that most male voters are confused about their sexual orientation :)
In my program I am using the do-while loop to go through program..
my question is how do I loop the program without the do-while loop...
rather that when the user enters menu number 0, it quits the program...
Teacher uses a script to grade the programs and on hsi example it just runs over and over without it asking "continue?"any advice?
you could replace the do-while loop with a simple loop that never ends. Is that what you mean? But having a Quit option I think is a better solution because it tells the user how to exit the program.
while(1)
{
// do something
}
>>Edit: made a smiley out of my parenthesis :O
That happens a lot. If you scroll down the page you will see a checkbox to disable smilies in text. You may have to click the Go Advanced button to see that checkbox.
>>How about this way...
You will have to try it to find out because I don't know if that will work or not with the most recent version of MFC supplied with VC++ 2005. Microsoft made a lot of changes to it, including making it a template instead of a c++ class.
CString mystring = _TEXT("Hello World");
string astring = (LPCTSTR)mystring; // assuming UNICODE is NOT defined
or
string astring = mystring.GetBuffer(0);
>>I'm still gettin fopens deprecated though
That's only a Microsoft thingy -- C and C++ standards make no such claim. You can use a pragma to disable that warning #pragma warning(disable: xxxx)
just replace the x's with the warning number.
>>base ( super ) classes dont know about their subclasses, they don't generally have a type-safe pointer to the fully extended class..
I was thinking the other way around. A base class should never need to know about its children anyway. If you want the child to implement some feature then use pure virtual functions.
>>^^ try that, if you dont mind, when i try i get a
Yes I get that warning. And I think it is because the class has not been fully constructed. But this works without that warning
class foo
{
public:
foo(){ myself = this;}
private:
foo * myself;
};
>>Is it difficult
Never tried what you want to do, so I don't know.
>>I'm sure it's what I need but I don't really understand how strstr works
Very simple -- it searches through the string in the first parameter for the first occurrence of the string in the second parameter. If the first string contains the second string then strstr() will return a pointer to the start of that string. If it is not found then strstr() will return NULL.
Example:
strstr("Hello World", "is"); // return NULL because "Hello World" does not contain the word "is"
strstr("Hello World", "orld"); // will return something other than NULL because "Hello World" does contain the string "orld". Note that this does not have to be an entire word but any sequence of characters.
If you want to use command-line arguments where the first argument is a filename and the seocnd argument is the string you want to find, to modify Narue's code a bit
int line_number = 0;
FILE* in = fopen(argv[1],"r");
while ( fgets ( line, sizeof line, in ) != NULL ) {
++line_number;
if ( strstr ( line, argv[2] ) != NULL ) {
printf ( "%d: %s", line_number, line );
fflush ( stdout );
}
}
>>I feel like I need more substance in my main to make it work
I think you are trying to make a mountain out of a mole hill :)
you have to iterate through the directory and delete them one at a time. See FindFirstFile() and FileNextFile() to iterate through the directory.
what version of vc++ are you using. The code below compiles ok without warnings with vc++ 2005 express
class foo
{
public:
foo() {this->x = 0;}
private:
int x;
};
int main()
{
foo f;
return 0;
}
>>I want to pass 'this' of a class one of its superclass's constructors
why? it already knows about the base class so there is no reason to do that.
>>what does he mean by this
why don't you ask him? But my guess is that you need to add three functions, two functions each return an int and the other function is void
int function1()
{
return 0;
}
int function2()
{
return 0;
}
void function3()
{
}
What version did you download? Windows or *nix? If you downloaded Windows version use WinZip to decompress the library and WinZip will create all the necessary directories. If you downloaded the *nix version then I think you use tar command to decompress it. For more information you need to read the documentation here. If you indend to use these types of libraries then you might as well get used to doing a lot of reading and studying. It ain't as easy as executing a install.exe program. You have to learn to think about what you are doing.
Exactly how to do this depends on the compiler yoj are using. What compiler do you have installed on your computer and what operating system?
Is there a function in C++ where a string can be held in a Unsigned array?
I don't know how that relates to your original question, but its not called a function but a container. such as vector<string> array;
. Or if you mean you want to put a c-style null-terminated string into an array, then try vector<char*> array;
>>I dont get it!
>>I need this program to be able to display 4th quarter inventory
The 4th quarter is the three months October, November and December. You have an array values that contains all 12 months. So the last three months are values[9], values[10] and values[11]. So display each of those values as indicated in your original post. And do that just before the line system("pause");
>>for ( int month = 1; month <= N_MONTHS; month++
Array elements start at 0, not 1 and that loop should too for ( int month = 0; month < N_MONTHS; month++ )
>> cout << N_MONTHS+9 << endl;
What is that supposed to be? Why display the number 21 (which is N_MONTHS+9)?
>>Where am I doing 9 to 12?
You aren't and that's one of the problems. You need to add it to the end of the program that you posted.
We have already given you some hints. Now start studying your textbook from page 1 and don't skip ahead. You have to do some studying on your own.
why not just put the whole main program inside a do while loop. then place your question before the program ends
I think that's what I just said. :)