Using an IDE shows that you are "weak" in that you need auto-completion, syntax highlighting, etc...
I don't think using all of the tools available means you're weak. Programming is hard enough as it is, so why not get all the help you can? :)
Using an IDE shows that you are "weak" in that you need auto-completion, syntax highlighting, etc...
I don't think using all of the tools available means you're weak. Programming is hard enough as it is, so why not get all the help you can? :)
These days I am trying to solve as many questions as possible as I learn more from it.
You're not solving anything by asking someone else do to it. And you're not learning anything either. _And_ you're spamming.
I'm curious to know what it is about that page that works better for you than the list of recent posts in your subscribed forums, for example.
I like the real time aspect of who's online. The list of recent posts in my subscribed forums doesn't show me who's replying or creating a thread right now, it only shows me who's already posted.
I would think the latter makes it easier to see exactly what you're looking for instead of trying to wade through a list?
If I only follow the people in like tech talk or coffee house, the list is smaller and it's easy to look for 'replying' or 'creating thread'. :)
toppings[z] = a[z] ;
If a is declared as a plain int, why are you subscripting it like an array of int? I think you should make the whole thing an array and that'll fix your problem.
void Pizza::set ( int x , int y , int a[] , int i );
void Pizza::set ( int x , int y , int a[] , int i )
{
type = x ;
size = y ;
for ( int z = 0 ; z < i ; z++ )
toppings[z] = a[z] ;
}
pizza.set ( x , y , a, i ) ;
How's that? can you show an example?
I can't, but my teachers like to say that if you don't do something right the first time, you end up doing it again and again to fix the problems. It seems to me that using an array is bad because you lock yourself into a buffer size, and using allocated memory is bad because you have to work harder to make it work right and keep it working. The C++ string fixes both of those because it grows on its own and you don't have to manage it.
I don't think std::string class will work with binary data like that. I think the += operator will stop when it encounters the first 0 byte in the iobuf.
Yeah, I tried it. But assign and append let you pick a count for the incoming string. This works. :)
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
#define SETUP 1
int main() {
string contents;
#ifdef SETUP
ofstream binaryOut( "binary.dat", ios::binary );
contents.assign( "C code.\0C code run.\0Run code run.", 33 );
binaryOut.write( contents.data(), contents.size() );
binaryOut.close();
#else
ifstream binaryIn( "binary.dat", ios::binary );
// Get the binary data
char iobuf[1024];
do {
binaryIn.read( iobuf, sizeof( iobuf ) );
contents.append( iobuf, binaryIn.gcount() );
} while ( binaryIn );
binaryIn.close();
// Print the characters
for ( int i = 0; i < contents.size(); ++i ) {
if ( !isprint( contents[i] ) ) {
cout<< int( contents[i] );
} else {
cout<< contents[i]; …
system("pause"); //stdio.h
system is in stdlib.h, not stdio.h. It's not a good idea either because now you depend on an outside program that might be malicious. It's a big security no-no because you created a hole that hackers can use to break into your program. :(
So I put that into the " " and I get a whole slew of errors!
Right, because you have backslashes in the string. C# sees that and doesn't recognize them as escape characters, so it throws up compilation errors. To get a literal backslash you escape the character with a backslash or use a verbatim string. Escaping looks like this.
"Data Source=.\\SQLEXPRESS;AttachDbFilename="C:\\Documents and Settings\\Drummer Boy\\My Documents\\Coastal.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True"
A verbatim string looks like this.
@"Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Documents and Settings\Drummer Boy\My Documents\Coastal.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True"
It's a character string? Just set the first character to be a terminator and it'll be treated as "".
name[0] = '\0';
If it's a C++ string you can call the clear method and that truncates the string to be "".
name.clear();
There might be a way in the STL to do it, but I don't know. I'd write a search function that finds every occurrence of "is" and then checks to see if the first and last letters are on a word boundary.
#include <string>
#include <cctype>
using namespace std;
// Check if a series of characters is on a word boundary
bool isWord( string source, int start, int length ) {
bool isLeftBoundary = ( start == 0
|| isspace( source[start - 1] )
|| ispunct( source[start - 1] ) );
bool isRightBoundary = ( start + length == source.length()
|| isspace( source[start + length] )
|| ispunct( source[start + length] ) );
return isLeftBoundary && isRightBoundary;
}
// Find the starting index of a word in the string
int findWord( string source, string word ) {
int index = 0;
while ( ( index = source.find( word, index ) ) != string::npos ) {
if ( isWord( source, index, word.length() ) ) {
return index;
}
index += word.length();
}
return string::npos;
}
what i want to be sure is, after function statements does the allocation space dissapear?
No, it doesn't. But you _do_ lose the only reference to the space you had, and that's called a memory leak because now it's allocated and won't be freed until the program ends. If your OS doesn't free all memory allocated to a process when it's done, the memory won't be freed until you reboot.
In your program you'll get an exception on top of the memory leak because outside the function ucBufr will still be null. That's because when you passed the pointer to Allocation, it made a copy of the pointer to allocate memory to. When the function returns, that pointer is lost and the original ucBufr is still what it was before.
Your function just takes a pointer and allocates memory to it so you don't need to use a parameter at all. You should make the pointer in the function and then return it so you don't have to use double pointers to keep from losing the reference.
unsigned char *Allocation( void ) {
unsigned char *ucBufr;
/* nDataSize and ucData is got from a file here. */
ucBufr = malloc( nDataSize );
ucBufr[0] = 'B';
ucBufr[1] = 'U';
memcpy( ucBufr + 2, ucData, nDataSize );
/* ... */
return ucBufr;
}
after function statements local variables which are defined in the function are freed by the O/S.
Local variables aren't freed after a function returns. What happens …
You can chain joins together and the next join works on the result of the last join.
SELECT *
FROM thresholdTable INNER JOIN Configuration
ON Configuration.Configuration = thresholdTable.Config INNER JOIN Consistency
ON Consistency.Consistency = thresholdTable.Consistency;
The intermediate table that you join Consistency to is the result of joining thresholdTable and Configuration. If you wrap it in parentheses it's like this guy.
((a INNER JOIN b ON a.col = b.col) INNER JOIN c ON c.col = a.col);
but i don't know how to create the text file from my program...
If you open a file for reading, C++ assumes the file exists. If you open it for writing, the file is created if it doesn't exist. If your open mode contains ios::out or ios::app then it's opened for writing and the file is created if it doesn't exist.
When your program ends it automatically ends the file.
Just because C++ does things for you doesn't mean you should take advantage of it. ;) I think keeping symmetry makes the logic easier to follow. It's also good for consistency with things like returning from main even though you don't have to.
I suggest that you use the a structure or a class to write a object into the fil because when you read data from the file it would be easier to get the data.
Yeah, but if the object isn't a POD type the program might or might not work. It's safer to serialize the object into a character array or xml or something like that to avoid problems and still keep it simple. And it's better to use text than binary because it's portable and readable outside of the application. :)
I have to agree because you proved me wrong. You can't change things like the click event for the button but you can hook events further down the line and do stuff.
You need to include stdlib.h. The error cryptically tells you that malloc wasn't declared and the compiler just assumes it's a function that returns int and casting from int to char* isn't friendly.
I want it to return the value for the array.
Why? The only thing I can think of is that you want a copy of the array instead of something that changes the array owned by the testCase class. If that's the case, you should still return the address of the array because that's how arrays work, but you still have to make a new array.
int **testCase::population() {
// Make the first dimension
int **copy = new int*[3];
for ( int i = 0; i < 3; ++i ) {
// Make the second dimension
copy[i] = new int[2];
for ( int j = 0; j < 2; ++j ) {
copy[i][j] = matrix[i][j] = rand() % 2;
}
}
return copy;
}
That returns the dynamic array by pointer, but it's still a copy of the original array. You have to remember to free the memory so that's not a good way to do it. A better way is a vector object.
vector<vector<int> > testCase::population() {
vector<vector<int> > copy = vector( 3, vector<int>( 2, int ) );
for ( int i = 0; i < 3; ++i ) {
for ( int j = 0; j < 2; ++j ) {
copy[i][j] = matrix[i][j] = rand() % 2;
}
}
return copy;
}
If you don't want a copy, why do you want to return the array by value?
Use the Contains method of the string class to find substrings.
string s = "Hello World!";
if ( s.Contains( "Hello" ) ) {
Console.WriteLine( "Found \"Hello\" in the string" );
}
i also knw..but i wan to c the full program ma...
I think Ancient Dragon was trying to say that he won't do everything for you because it's your homework and not his. If you do some of it yourself then I think the guys here will be more willing to help you.
I remember hearing that you have to ask cin to throw away the enter or something?
Yeah something like that. Try adding cin.ignore like this.
cin >> choice;
cin.ignore( 80, '\n' );
For a queue just think of stuff where something goes in one end and out the other in order. For a stack just think of stuff where something goes in one end and out the same end in order.
You can find out where the exe is with command line arguments.
#include <iostream>
using namespace std;
int main( int argc, char *argv[] ) {
cout<< argv[0] <<endl;
return 0;
}
Once you have that string, you can trim off the filename and then have a path for storing the files. :)
I was playing with a bunch of new things today and came up with this. Did I do anything wrong?
/*
binary class manipulator
Print values or strings as binary
by Kimberly Hamrick
*/
#include <iostream> // for C++ I/O
#include <string> // for C++ strings
using namespace std;
namespace hamrick {
template <typename T>
class binary {
public:
explicit binary( const T value, const char *sep = " " )
: _value( value ), _sep( sep ) {}
friend ostream& operator<<( ostream& os, const binary& b ) {
return b._manip_value( os, b );
}
private:
const T _value;
const char *_sep;
ostream& _manip_value( ostream& os, const binary& b ) const {
// Print each bit of the value
// Separate bytes by b._sep
for ( int bit = sizeof b._value * 8 - 1; bit >= 0; --bit ) {
os<< ( ( b._value & ( 1 << bit ) ) != 0 );
if ( bit % 8 == 0 ) os<< b._sep;
}
return os;
}
// Hide the assignment operator because of warnings
binary<T> operator=( const binary<T>& );
};
template <>
class binary<string> {
public:
explicit binary( const string& value, const char *sep = " " )
: _value( value ), _sep( sep ) {}
friend ostream& operator<<( ostream& os, const binary& b ) {
return b._manip_string( os, b );
}
private:
const string _value;
const char *_sep;
ostream& _manip_string( ostream& os, const binary& b ) const {
// Print each bit of each character …