It compiles and runs fine if I try to write a set string to the file, such as "Hello", but it won't take the contents of the text box...
I have searched and read nearly everything I could find on the error on Google, but it seems as though it is a different fix every time, none of which really apply to my situation.
Hi and I have a hex to int function but it isn't converting the hex to integers properly. Below is the code an example is the hex bb76e739 which should = 3145131833 but with the function it equals 2147483647. I heard sprintf or something like that can convert the hex to int and assign it to a variable but have no code for it. Below is my current function which doesn't always work.
long hex2int(const std::string& hexStr) {
char *offset;
In my assignment I am supposed to use a pointer to create a 2-D array dynamically. Initialize each element in the array to the sum of its row and column. Then display each element of the array on the console.
I have the program written and it works except for the part that says initialize each element in the array to the sum of its row and column.
For the life of me I cannot wrap my head around how to do that. Can anyone give me a little help or suggestion as to a best method. I have set it to initialize everything to zero at the moment.
I tried doing this with no success
for (int j=0;j<5;j++) //initalize array elements to sum of row and column
{
for (int i=0;i<5;i++)
p[i][j]=i+2;
int main(int argc, char *argv[])
{
int pid;
pid_t pid_chk;
int pid_array[2];
int count[25], length, i, j;
for (i=0; i<3; i++) {
pid_array[i] = 0;
}
for (i=0; i<3; i++) {
for (j=0; j<=25; j++)
count[j]=0;
//fork();
if ((pid=fork())==0) {
/* child code */
// Store the PID of newly created child in an array.
pid_chk = getpid();
cout << "My process id is : " << pid_chk << endl;
cout << "Value of i is : " << i << endl;
pid_array[i] = pid_chk;
cout << "Value of pid_array is : " << pid_array[i] << endl;
//break;
kill(pid_chk, SIGKILL);
}
else {
// Parent's code
// Do nothing
}
}
{linux0:~/proj} trial_suggestion
My process id is : 10106
Value of i is : 0
Value of pid_array is : 10106
My process id is : 10107
Value of i is : 1
Value of pid_array is : 10107
My process id is : 10108
Value of i is : 2
Value of pid_array is : 10108
0
0
0
int main()
{ string s = "12a34b56c78d";
int size = 12;
writeStuff(s,size);
return 0;
} // end main
void writeStuff(string s, int size)
{ if (size > 0)
{ cout << s.substr(size-1, 1);
writeStuff(s, size-3);
} // end if
} // end writeStuff
[code]int main()
{
recurse(5,3);
return 0;
} // end main
void recurse(int x, int y)
{ if (y > 0)
{ ++x;
--y;
cout << x << " " << y << endl;
recurse(x, y);
cout << x << " " << y << endl;
} // end if
} // end recurse[/code/
What is the output?
ok how will i keep track of the items i bought? i have not the slightest clue on that. i dont even know where to start.
can someone point me in the right direction?
#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit,;
double mug = 2.50f, teeshirt = 9.50f, pen= 0.75f,tot_mon = 30.0f;
cout << "You have 30 dollars to spend.\n";
do
{
cout << endl;
cout << "What do you want to buy today?\n";
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> symb;
switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n" << endl;
tot_mon -= mug;
cout << " You have " << tot_mon << " remaining \n" << endl;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 " << endl;
tot_mon -= teeshirt;
cout << " You have " << tot_mon << " remaining \n " << endl;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents " << endl;
tot_mon -= pen;
cout << " You have " << tot_mon << " remaining \n " << endl;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
tot_mon = 0;
break;
I use a panel and if the user Leftclicks an area with the mouse, I am trying to set the variable LeftRightClick to "Left" and the same for rightclick, "Right".
Then I call the button43_MouseDown event to show the correct MessageBox, depending on if it was a leftClick or RightClick.
When doing this the messageBox: MessageBox:: Show("LeftClick");
is always shown even that a rightclick was made.
Can someone quickly point out what the problem is here? I'm sure it's something small but I've been coding for too long to see it.
The problem is that in the balance method call, the first parameter is an array. if I hard code a test array, or if I create a test pointer array and fill it, the program works fine, but if I pass the pointer as I am here, I get output problems. To much detail to get into now but I'm sure it's something to do with these array pointers I'm messing with. I think the pointer is somehow being passed in as empty or as a single value, in stead of a whole list of values. I'm still new at pointers so be easy on me.
this->wordArrayLength++;
string* tempArray = new string[this->wordArrayLength + 1];
for (int i = 0; i < this->wordArrayLength; i++ ) {
tempArray[i+1] = this->wordArray[i];
cout << tempArray[i] << endl;
}
int counter = 0;
for (int i = this->wordArrayLength -1; i > -1; i-- ) {
this->wordArray[counter] = tempArray[i];
counter++;
}
for (int i = 0; i < this->wordArrayLength; i++ ) {
tempArray[i] = this->wordArray[i];
//cout << tempArray[i] << endl;
}
delete []wordArray;
this->wordArray = tempArray;
int* levelNums = new int[2]; //create new array to hold tree level index numbers - starts at 1 (1st level)
levelNums[1] = '\0';
int levelNumsLength = 1;
How would i keep track of money spent? and items bought when i loop and how do i say i want multiple items meaning if i want to purchase more than one teeshirt or mug.
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/
#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit, answ;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
cout << "You have 30 dollars to spend.\n";
do
{
cout << endl;
cout << "What do you want to buy today?\n";
tot_mon = 30;
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> symb;
switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n" << endl;
mug = 2.50;
curr_cash = tot_mon - mug;
cout << " You have " << curr_cash << " remaining \n " << endl;
tot_mon = 30;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 " << endl;
teeshirt = 9.50;
curr_cash = tot_mon - teeshirt;
cout << " You have " << curr_cash << " remaining \n " << endl;
tot_mon = 30;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents " << endl;
pen = .75;
curr_cash = tot_mon - pen;
cout << " You have " << curr_cash << " remaining \n " << endl;
tot_mon = 30;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
quit = 0;
break;
default:
cout << "Input error. Select again" << endl;
}
if ( curr_cash = 0)
{
cout << "You need more cash, you dont have enough\n" << endl;
curr_cash = tot_mon - mon_spent;
}
else
{
cout << " Would you like anothe purchase, please choose another letter.\n" << endl;
New to templates and lists but i have to use them for a class project. I got it working in one file then i tried to make it a class and I keep getting this error:
1>c:\users\r4ck13y\programming\c++ projects\project2.1\project2.1\merginglists.h(11) : error C2955: 'std::list' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 9.0\vc\include\list(95) : see declaration of 'std::list'
Here is the header file that im about 90% sure the error is coming from. Please help. Thank you.
Hi, I'm having a problem with displaying names from a text file. I'm passing the names from the text file to an array that will be sorted, but I'm not getting the names to show like I want them to.
It should display the different names as Last, First
But it comes up as
Last,
First
I believe that I'm not passing the names from the text file to the array properly, but I'm not sure what I should do.
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
//Input file stream object
ifstream inputFile;
//constant for number of names
const int NUM_NAMES = 20;
//array that holds names
string names[NUM_NAMES];
//open the file
inputFile.open("namesFile.txt");
// Read names from file into array
for(int count = 0; count < NUM_NAMES; count++)
inputFile >> names[count];
//close file
inputFile.close();
cout<<"Unsorted names :\n\n";
//show and then sort names
showArray( names, NUM_NAMES );
selectionSort( names, NUM_NAMES );
//clear screen for readablity
system("cls");
//show sorted names
cout<<"Sorted names :\n\n";
showArray( names, NUM_NAMES );
return 0;
}
I'm not looking for someone to do my homework for me, I just need a push in the right direction.
Is there anyone out there that finds Visual C++ (ver8) Debugger broken? Specifically with regard to variables out of scope.
I have asked here about specific problems and none of the proposed solutions work. The debugger works on the easiest of things, but half the time, things that are obviously in scope, it complains that they aren't.
The only people who respond, obviously the debugger works for them and I appreciate their advice. But let me see if there's anyone else that has to spend half the day displaying variables with code because the debugger won't.
Im trying to figure out how to error trap this program so if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly.
also i want to subtract the money they spend and tell them their remaining amount, also i want to keep track of the number of items they purchase.
when i do it all that comes up is a whole bunch of numbers.
can anyone help when you compile this program i want this format but the numbers arent right
can anyone help?
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/
#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
cout << "What do you want to buy today?\n";
cout << "You have 30 dollars to spend.\n";
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> symb;
switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n";
mug = 2.50;
cout << " You have " << curr_cash << " remaining \n ";
tot_mon = 30;
curr_cash = tot_mon - mug;
cout << " You have purchased " << numb_item_purch << " today \n ";
numb_item_purch = item_purch + 1;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 ";
teeshirt = 9.50;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents ";
pen = .75;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
quit = 0;
break;
}
I'm writing a C++ program in which I need to display the bits that represent both a 32-bit and 64-bit floating point number. I had no problem properly displaying the 32-bit number, but I'm having trouble with the 64-bit number.
This is the code that I'm trying to use:
unsigned int* low = (unsigned int*)&doubleValue;
unsigned int* high = (unsigned int*)((&doubleValue)+4);
unsigned int mask = 0x80000000; // 1000 0000 0000 0000
unsigned int result;
The variable 'doubleValue' is of type double and holds the number that I am trying to display in binary. I can get the lowest 32 bits to display correctly, its the highest 32 bits that I'm having trouble with.
Im trying to figure out how to error trap this program so if the user doesnt put in a valid response then a message will cum up and they will go back 2 the beginning until they do it correctly.
also i want to subtract the money they spend and tell them their remaining amount, also i want to keep track of the number of items they purchase.
when i do it all that comes up is a whole bunch of numbers.
can anyone help when you compile this program i want this format but the numbers arent right
can anyone help?
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/
#include<iostream>
using namespace std;
int main()
{
char symb;
int item_purch, numb_item_purch, quit;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
cout << "What do you want to buy today?\n";
cout << "You have 30 dollars to spend.\n";
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> symb;
switch (symb)
{
case 'A':;
case 'a':;
cout << " You have choosen A) mugs for $2.50 \n";
mug = 2.50;
cout << " You have " << curr_cash << " remaining \n ";
tot_mon = 30;
curr_cash = tot_mon - mug;
cout << " You have purchased " << numb_item_purch << " today \n ";
numb_item_purch = item_purch + 1;
break;
case 'B':;
case 'b':;
cout << " You have choosen B) teeshirt for $9.50 ";
teeshirt = 9.50;
break;
case 'C':;
case 'c':;
cout << " You have choosen C) Pens for .75 cents ";
pen = .75;
break;
case 'D':;
case 'd':;
cout << " You have choosen D) which means you want to Quit" << endl;
quit = 0;
break;
}
I am making a pong-like game for a class.
I am having trouble with the ball's collision detection.
The game is a 1 player version, where the ball and paddle are both contained in a box. The player uses a gun which is built into the paddle, in order to shoot a hole through the back wall so that the ball may escape (earning them a point)
I have also given the paddle 2-D movement, instead of just along the x-axis.
The ball seems to be bouncing off the side walls fine, but when it hits the top wall, it seems to "reset" the ball, and it just reappears near the paddle and starts moving again.
I also notice that when the ball is reflected off a wall toward the paddle, it seems to be attracted to the paddle like a magnet.
I tried to post my code, but it was giving me some error about "you do not have permission to create tags" or something like that.
I am wondering if there is a way to detect collision, based off of getpixel(), but for more than one pixel at a time. For example, since the ball is circular, instead of just testing one pixel in the direction that the ball is going, is it possible to getpixel() for a specific area of pixels instead of just one single pixel at a time? Does my question make sense?
i need help creating a rectangle where the user creates the border and fills in the empty space with any symbol they want.
it should look like this
#######
#@@@@#
#@@@@#
#@@@@#
#######
mine only looks like this
#
@@@@@
#
@@@@@
#
@@@@@
any help??? heres my code:
char b;// character used to draw border of rectangle
char f;//character used to fill the rectangle
cout << "What character would you like to use to draw the border of your rectangle?";
cin >> b;
cout << "What character would you like to use to fill the rectangle?";
cin >> f;
for (int i = 0; i < rectangleLength; i++)
{
cout << b;
cout <<"\n";
I need assistance with the assert function. The question is convert a date to Julian date and then check which one is the smallest and subtract to show the different days. That is all done. The part I have no idea is how to use the assert function to verify that the dates entered are legitimate dates.
Is there someone that can assist me please.
//Converting date to Julian format
#include <iostream>
#include <assert.h>
using namespace std;
//definition for the number of days in
//each month
int daysPerMonth[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int calcJulian(int dd, int mm)
{
int t = 0;
int numDays;
for (int i = 1; i < mm; i++)
{
switch(i)
{
case 1: numDays = daysPerMonth[0];
case 3: numDays = daysPerMonth[2];
case 5: numDays = daysPerMonth[4];
case 7: numDays = daysPerMonth[6];
case 8: numDays = daysPerMonth[7];
case 10: numDays = daysPerMonth[9];
case 12: numDays = daysPerMonth[11];
t += 31;
break;
case 4: numDays = daysPerMonth[3];
case 6: numDays = daysPerMonth[5];
case 9: numDays = daysPerMonth[8];
case 11: numDays = daysPerMonth[10];
t += 30;
break;
case 2: numDays = daysPerMonth[1];
t += 28;
break;
}
}
t += dd;
return t;
}
int g = calcJulian(dd2, mm2);
cout << "Julian day: " << f << endl;
cout << "Julian day: " << g << endl;
//check which is the smaller date and then subtract
//to get the different between the days
float ans;
if ( f < g ) {
ans = (g-f);
}
else {
ans =(f-g);
}
cout << "Numbers of days different between the two days is: " << ans << endl;
I am very new to C++ and would like to know how to handle the following:
Let's say I have a button on a form. When the user clicks the button, a new textbox is created on the form. How can I add event handling for this new text box?
How can i make this into a menu where you select a letter and you get a response that reads
you have choosen "a" which is $2.50
/* SIUE's bookstore is having aspecail sale on tiems embossed with the cougar logo. For a limited time, three items, mugs, teeshirts, and pens
are offered at a reduced rate with tax included to simplify the sales. Mugs are going for $2.50, teeshirts for $9.50 and pens for 75
cents. Coincidentally, your parents (or spouse, friend, coworker, or other person you know off-campus) just gave you $30.00 to buy SIUE
stuff for them.*/
#include<iostream>
using namespace std;
int main()
{
char symb,symb1, symb2, symb3;
int item_purch, numb_item_purch, quit;
double mug, teeshirt, pen, tot_mon, curr_cash, mon_spent;
cout << "What do you want to buy today?\n";
cout << " A) Mugs $2.50 " << endl;
cout << " B) teeshirt $9.50 " << endl;
cout << " C) Pens .75 cents " << endl;
cout << " D) Quit" << endl;
cout << " Enter your letter and press Return when finished" << endl;
cin >> mug;
cin >> teeshirt;
cin >> pen;
cin >> quit;
mug = ('A' || 'a');
teeshirt = ('B' || 'b');
pen = ('C' || 'c');
{
if ((mug == 'A') || (mug == 'a'))
{
I've been writing some code in C++ to test the tffs-lib library, which is written in C. The library provides functions for directly accessing a FAT file system from within a program. Although most modern operating systems have drivers for accessing the FAT filesystem on SD cards, I am working with an embedded Linux system, and I would like to directly access the FAT filesystem using a device node (/dev/mmcblk1p1) to speed up write I/O access.
I am able to build the tffs-lib and statically link it with my test program. My cross-compiler build is based on gcc 4.2.2.
However, I receive the following error when compiling the code. This error mentions an "anonymous struct," which I believe is not legal in C++.
request for member 'fatsz' in 'htffs', which is of non-class type '<anonymous struct>*' test.cpp test-tffs-lib
Is it possible to use an anonymous struct in C++, even when the anonymous struct is being used within a C library? I tried passing the command-line switch "-features=extensions" to gcc, but (strangely enough) this results in no executable being created. However, after passing this switch, there is no warning generated, and the code compiles cleanly (without the output executable being created.)
Here is the code of my very simple test program in C++. The error occurs on line 32 below.
#include <iostream>
#include <string>
// TFFS library include (for C code)
extern "C" {
#include <tffs.h>
}
but when i put this line in the header file, i get the following errors:
error: variable or field 'read' declared void
error: 'set' was not declared in this scope
error: 'string' was not declared in this scope
error: 'mySet' was not declared in this scope
Hi there
I want to use c++ to draw a path
The path is based on two variables, x and y
and x and y will change automatically every second
So I think the flow should be like this:
t=0, (x,y)=(0,0) ->draw a point on the graph
t=1, (x,y)=(2,2)->draw another point on the graph
....
repeat the above steps until the user stop the program.
But I have no idea how can I ask the program to draw point every second and keep all the points in the graph? I tried to use a timer
I wonder if anyone can help me. I'm suppose to write a program to ask the user to enter the file they want to display and display the file they want 24 lines at a time. It pauses at 24 and asks them to press enter and displays the next 24 lines. I have a pretty good code I think for a beginner, but no matter what file I enter when I test the program it goes to the error checker and says it couldn't open the file. I will attach my code. If anyone has any tips I would appreciate it. Thanks.
//This program will write to a file and then
//ask the user to recall that file and display.
#include <iostream>
#include <fstream>
using namespace std;
//Constant for array size
const int SIZE = 100;
int main()
{
char MyFile[SIZE]; //Hold the file name
char inputLine[SIZE]; //To hold the line of input
fstream address; //File stream object
int line = 0; //Line counter
char ch; //To hold a character
address.open("address.txt", ios::out);
address<<"Anthony Smith "<< endl;
address.close();
//Get the file name.
cout<< " Enter the name of the file you are";
cout<< " interested in.\n";
cout<<" ";cin.getline(MyFile, SIZE);
//Open the file.
address.open(MyFile);
//Test for errors
if(!address)
{
cout<<" There was an error opening "<< MyFile << endl;
exit(EXIT_FAILURE);
}
else;
{
address.get(ch);
}
//Read the contents of file and display
while(!address.eof())
{
//Get a line from the file.
address.getline(inputLine,SIZE,'\n');
//Display the line.
cout<< inputLine << endl;
//Update line counter
line++;
//Display 24 lines at a time.
if(line == 24)
{
cout<< " Press enter to continue.\n";
cin.get();
line = 0;
}
}
Hi,
I'm able to write a copy constructor for a class which contains pointer as a data member. However, when I have a reference as a data member, the copy constructor does not help, i.e. when I change that member for one object, the change is reflected in another one also.
Please refer to the code below.
class Student {
private:
int roll_no;
char *pname;
int & marks;
public:
Student():marks(a) {
roll_no = 0;
pname = new char[7];
strcpy(pname, "no one");
}
Student(int a, char *p, int &m):marks(m)
{
roll_no = a;
pname = new char [strlen(p) + 1];
strcpy(pname,
}
Im pretty new to c++ programming so plz dont be offended if i ask "stupid" questions.
Im want to open a file named "Alexander".
The name of the file is stored in an Ansisting.
So i want to add an ".txt" extension to open the file.
Then i want to read a line form the file and store it in an string named StringFromFile.
After reading it i figured out that this char array may be stored in read-only memory. So my question is: is the acces violation generated because om trying to add ".txt" to char* temp?
I already have a solution by using char temp[] but i would still like to understand why the acces violation was genereted!
MY problem is .....
Given an input 'n' came from the user and display a pattern.
but my code is very long .... my code is only for 1-10 numbers i need to display any numbers that input of the users can u give me some short code or advice to make it easy or briefly...Thxxxxx
Ex. if n=6, display
Ex. output
6 5 4 3 2 1
6 5 4 3 2
6 5 4 3
6 5 4
6 5
6
#include<iostream.h>
#include<conio.h>
main()
{
int n1,i;
char c1;
textcolor(YELLOW);
a:
clrscr();
cout<<"Enter a number :";
cin>>n1;
for (i=n1;i>0;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>1;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>2;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>3;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>4;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>5;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>6;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>7;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>8;i--)
{
cout<<" "<<i;
}
cout<<endl<<" ";
for (i=n1;i>9;i--)
{
cout<<" "<<i;
}
{
cout<<""<<endl<<""<<endl;
cout<<"Do you want to try another number or EXIT...?"<<endl;
b:
cout<<"Press 'y' if you want to try another number and 'n' to exit:";
cin>>c1;
if ( c1=='y' || c1== 'Y')
goto a;
else if (c1=='n' || c1=='N')
cout<<endl<<"Press Any Key to EXIT";
else
{
cout<<"Invalid input, Choose again"<<endl;
goto b;
}
}
getch();
}
hi, i need to send keystrokes an application (including, "enter", "left arrow", "right arrow", etc).
but how do i do that? i do not see any short and useful examples to doing it.
all i have got at the current moment is to get the foreground window using
HWND foregroundWindow = GetForegroundWindow();
i see the PostMessage function takes in HWND, UINT, WPARAM and LPARAM... but i have no idea which is for what. can somebody pls explain and teach me how to send keystrokes to an arbitrary application?
then test whether they are equal. I'm really very bad at computer errors, I think I need to read more about it (any reference is welcome). So, my question is: What is a suitable EPSILON to tolerate some computational errors in general? I know this depends on the complexity of the operation itself (because of propagating the errors at different steps of computation)... but what is a suitable start?
HEllo everybody !!!
i have a little problem..
i m making a program in which i have to do bitwise addition.
mean if the 1st input is 111 and the 2nd input is 11 then the output is 1010 i have made my logic but where i have the problem is that i have to take the input in a single array and where the user enters the space it means that the input in 1st array has been ended and the input of second array is upto \0 i dont understand that how i check where the user enters the space thats the problem...
so kindly somebody plz explain it that how i will do this.....
thnx in advance
Hello all,
I have registerd lately, we have a project about the implemention of huffman algorithm...!
I have some problem...
first is that I want to read space and Enter from txt file how can i do that?
Next is how i should output to say that 0 and 1 are bit no byte!..
and finally how can i print huffman tree ... ?
Excuse me for elemntary question...
Tnx a lot...
Hi guys, I am supposed to implement a sequence using linked list. But I seem to have an error in the code. As I am getting trash for the results of the concatenate function. It might be a problem with my constructor too. I am not sure. Please help. I have pasted the code.
#include <iostream>
using namespace std;
typedef int ElementType;
struct Node
{
ElementType data;
Node* next;
};
class Sequence
{
public:
Sequence();
Sequence(ElementType s);
~Sequence();
Sequence concatenate(Sequence &s);
void insert(ElementType s);
ElementType remove();
bool isEmpty();
void printSeq();
private:
Node* head;
};
#include "sequence.h"
Sequence::Sequence()
{
head = NULL;
}
Sequence::~Sequence()
{
while(head != 0)
{
Node* iter = head;
head = head->next;
delete iter;
}
}
Sequence::Sequence(ElementType s)
{
Node *temp = new Node;
temp->data = s;
temp->next = head;
head = temp;
}
void Sequence::insert(ElementType s)
{
Node *temp = new Node;
temp->data = s;
temp->next = head;
head = temp;
The function I am trying to write is supposed to be recursive and does the following:
Return the number of ways that all n2 elements of a2 appear in the n1 element array a1 in the same order (though not necessarily consecutively). The empty sequence appears in a sequence of length n1 in 1 way, even if n1 is 0.
For example, if a1 is the 7 element array
"Bart" "Lisa" "Maggie" "Marge" "Lisa" "Maggie" "Homer"
then for this value of a2 the function must return
"Bart" "Marge" "Maggie" 1
"Bart" "Maggie" "Homer" 2
"Marge" "Bart" "Maggie" 0
"Lisa" "Maggie" "Homer" 3
So far, I have written this much:
int countIncludes(const string a1[], int n1, const string a2[], int n2)
{
if (n2 == 0)
return 1;
if (n1 == 0)
return 0;
else
{
if (a1[0] == a2[0])
return countIncludes(a1+1, n1-1, a2+1, n2-1);
else
return countIncludes(a1+1, n1-1, a2, n2);
}
}
But it is incomplete and I know it does not work properly. I need help figuring out how to do this problem--just a method about how to go about this would be extremely helpful.
Hi, I'm trying to create a simple program in Win32 and I can't find how to accept input in the form of text. Like "What's your name: ___" then the user enters their name and my program can evaluate the input. I have already googled this for a long time, so please don't give me lmgtfy answers. Thank you.
I know that Java and C# and various OTHER programming languages support a variable type Object, which is basically a variable that can hold ANY kind of variable type, from strings to booleans. I was wondering if this is possible in C++, I REALLY badly need something of that kind, anyone know where I can get something like that?
Can you please tell me what's wrong? I get this error:
error C2447: '{' : missing function header (old-style formal list?)
//
// Area= 1/2 | (x1y2 - x2y1) + (x2y3 - x3y2) + (x3y1 - x1y3) |
// (distance)^2 = (x-difference)^2 + (y-difference)^2
// v= sqrt[ s(s-a)(s-b)(s-c) ]
// c^2= A^2 + B^2 - 2 A B cos Z
// Z = angle between A and B
// area of triangle = 1/2 AB sin Z
#include <iostream>
#include <cmath>
using namespace std;
Hi there,
I am experiencing a problem during the program execution.
Here is the program:
#include <iostream>
using std::cout;
using std::cin;
int additions (int a, int b, int c)
{
int k;
k = a+b-c;
return k;
}
int main()
{
int s;
int x;
int y;
int z;
cout << "The first number is: \n";
cin >> x;
cout << "The second number is: \n";
cin >> y;
cout << "The third number is: \n";
cin >> z;
s = additions (x,y,z);
cout << "The result is: " << s << "\n";
if (s == 4)
cout << " \a\a\a";
return 0;
}
Basically, when I click on the exe file in the debug folder, the program doesn't execute properly: it asks for the first number, second and third and then when I click enter the terminal disappears (I am using windows XP and the compiler is VC++ 6.0 trial copy).
If I instead compile the program and run it from VC++ (with ctrl F5) everything goes well...what am I doing wrong?
Thanks
Ok so a little bit of background, I am trying to write a boggle solver, I had everything working until I tried to implement a Binary Search Tree for storing the words found on the board, when I tried to do this I got the following errors:
Error 1 error C2146: syntax error : missing ';' before identifier 'foundWord' line 24
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int line 24
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int line 24
boggle.h
#pragma once
#include<iostream>
#include<string>
#include<ctime>
#include<fstream>
#include"HashTable.h"
#include"SLL.h"
#include"BST.h"
Piece boggleBoard[3][3];
HashTable WordListHT; //Calls HashTable
string soFar;
BST foundWord; // Creating a Binary Search tree for any found words
public:
boggle(void);
~boggle(void);
void LoadWordList(string name);
void CreateBoard();
void PrintBoard();
void WordSearch();
void WordSearch(int i, int j); // overloaded function for recursive call during search
};
copy of BST.h
#pragma once
#include<iostream>
#include<string>
#include"boggle.h"
and just to make sure I'm not missing anything stupid
BST.cpp
#include "BST.h"
BST::BST(void)
{
root = 0;
}
BST::~BST(void)
{
}
void BST::Insert(string data)
{
Node* n = new Node;
n->element = data;
n->left = 0;
n->right = 0;
// Special case if root == 0
if(root == 0)
{
root = n;
return;
}
// Creating a new node for insertion
//Create tmp to traverse nodes
Node* tmp = root;
// Use a while loop to determine where the node is inserted
while(tmp) // While tmp has some value besides NULL(0)
{
// if data less then tmp->element then go left
if(data < tmp->element)
{
// if tmp->right == 0 then insert here
if(tmp->left == 0)
{
tmp->left = n;
return;
}
// else procede to next node
else
{
tmp = tmp->left;
}
}
// else go left
else
{
// if tmp->right == 0 then insert here
if(tmp->right == 0)
{
tmp->right = n;
return;
}
// else procede to next node
else
{
tmp = tmp->right;
}
}
}
}
The Binary Search Tree was originally intended to take ints, but for this project need it to take strings.
Hello, I am working on a program that takes an integer array filled from a random number generator. These values are suppose to be from -5000 to 5000, 2500 of them. Then I want to find the standard deviation of the numbers in the array. I am required to use and integer array, calculate the average, returns the average which is a floating point value. Then I calculate the standard dev. I am having a problem with casting certain values. I am suppose to use integers and floats and I can't get it to work. I pretty sure I am suppose to use static cast but it wasn't working so I took it out. Any help would be greatly appreciated, and imput would be great too. I really want to get this working, thank you.
heres my code:
Driver
// AUTHOR: Page Lynn Potter
// CLASS: CIS 2275 C++ II
// PROGRAM: Quiz #1 | C++ ...Standard Deviation
// E-MAIL: ppotter03@inbox.com
// FILE: Driver.cpp
#include <iostream>
#include <iomanip>
#include "Functions.h"
using namespace std;
int main()
{
// Declared Variables
int Numbers[2500];
int Total = 2500;
float StandardDev, Mean;
cout << "\n This program computes two statistical values for an array "
<< "\n of 2500 values rainging in value from -5000 to +5000. ";
cout << "\n The sum and average of the values will be calculated, "
<< "\n and diplayed for viewing as well as the standard deviation. \n";
void FillArray(int Numbers[], int Total)
{
srand(123);
for (int i = 0; i < Total; i++)
{
// Gives me 0 - 10000
Numbers[i] = ((rand()%10000 + 1) - 5000);
}
}
float AveArray(int Numbers[], int Total)
{
// Declared Variables
int sum = 0;
// Just to make sure there isn't any junk values.
float Mean = 0,0;
for (int i = 0; i < Total; ++i)
{
sum += Numbers[i];
}
Mean = sum/Total;
return Mean;
}
float StandardDev(int Numbers[], int Total, float Mean)
{
// Declared Variables
float StandardDev = 0.0;
int Sum2 = 0;
for (int i = 0; i < Total; ++i)
{
Sum2 += pow((Numbers[i] - Mean), 2);
}
StandardDev = sqrt(Sum2 / (Total - 1));
return StandardDev;
}
Header
// AUTHOR: Page Lynn Potter
// CLASS: CIS 2275 C++ II
// PROGRAM: Quiz #1 | C++ ...Standard Deviation
// E-MAIL: ppotter03@inbox.com
// FILE: Functions.h
#include <iostream>
using namespace std;
/* The FillArray() is passed the integer array and total number
(size) of the array. It then uses rand() to fill the array
with values from -5000 to +5000. */
void FillArray(int Numbers[], int Total);
/* The AveArray() calculates the average (mean) of the array.
It is passed the array, total number (size) and returns, a
floating point value. */
float AveArray(int Numbers[], int Total);
/* The StandardDec() is passed the array, array size, and the
average (mean) value. It then calculates and returns the
standard deviation. */
float StandardDev(int Numbers[], int Total, float Mean);
//Define a function that takes a partially filled array of numbers
//as its argument and returns the standard deviation of the numbers in
//the partially filled array. Since the partially filled array requires
//two arguments, the function will have two formal parameters: an array
//parameter and a formal parameter of type int that gives the number of the
//array positions used. The numbers in the array will be double. The task is
//the standard deviation of a list of numbers is a measure of how much the number
//deviate from the average. If the standard deviation is small the numbers are
//clustered close to the average and if the standard deviation is large, the numbers
// are scattered far from the average. The standard deviation, S,of a list of N
//numbers x, is defined as follows: where x is the average of N.
S = think square root symbol, N, sum(x, -x)to second power, i = 1, over N
I have not started the code yet as I have no real idea of what this wants .... if it could be explained or shown to me of what is required then I can start building code for this .... does anyone understand this enough to help me...
It looks impressive....
I was using Codeblocks.But it's lack of features and less frequent stable release has disappointed me.Though, it's subversion is very frequent.
I am no expert, but CodeLite looks better then codeblocks.
But, if it is better then codeblocks then why it is not popular as codeblocks or DevC++(whose stable release was many many years ago).
Any comments about this?
....and do anyone know something about Eclipse.It looks quite impressive.
I have to modify the program so that it can read 10 sample points and determine which are contained in the plume boundary. This is my first object oriented class and I have made it run ten times but I dont think that is correct. Please advise.... Thanks.
class Probe
{
private:
Point sample_pt, endpt1, endpt2;
int num_crosses;
Point probe_line_intersect (Line_seg);
int probe_line_seg_intersect (Point, Line_seg);
“Although for consistent and reusable design we follow Object Oriented paradigms; “structured approach” has still its worth in some imperative and critical applications. Support or contradict this statement with solid arguments.
Can anyone help me with this problem.For example i have a text file called food.txt with contents
1 apples
2 oranges
3 mango
4 bananna
What i would like to do is enter the choice of fruit into a string and loop through the file until the word is found.My problem being i dont fully understand any of the examples online and would be grateful if someone could point me in the right direction.
Many apologies if the question I am about to ask has already been answered. I searched the forum, and found a couple of threads that seemed to be relevant to my problem, but none seemed to describe the problem fully.
I'm fairly new to C++, having only been using it seriously as part of my studies for the past 6 months or so.
My problem is this. I have a class which must contain two arrays of integers, eg:
class myClass
{
public:
int firstArray[size];
int secondArray[size];
readValues();
};
The readValues function takes input from a text file containing a series of integers and should write it into the relevant array using ifstream. The problem is there is no way of knowing how many values will be in this text file beforehand. Having said that, the text file will not change in size during the program operation.
I'm not sure of the best way of approaching this. Is there a way of possibly defining that the array exists within the class, and define it's size later? Or can I define it later, either within the constructor or another function?
You help in solving this problem would be most appreciated.
I've been searching for reading number in a string containing mix of number and char for hours, but I've found the right code. The string has the format
q23 - q3 (or q23-q3)
I'd like to read the number '23' and store it in x, '3' --> y, and '-' --> z. Could you tell me how to do this?
Thanks!
I wrote some C++ programs and classes a few years ago using Visual C++ 6.0 as my editor/compiler. Recently I replaced the 6.0 with Visual C++ 2008 Express. Now, none of my older code will compile.
I read that there were some changes to the C++ standard library some time ago and I suspect the VC++ 2008's compiler incorporates these changes.
If I am correct, all I need is some documentation as to what was changed in the library so I can edit the source code and make it work again.
Can someone point me in the right direction so I can update my code to today's standards?
Thanks.
Uncle Ed
Hi I am trying to implement a sequence using a linked list. I need to have the following functionalities: insert, remove and concatenate. The concatenate should not be destructive and the function call should be like. That is Seq1 and Seq2 should be preserved post function call.
Seq3 = Seq1.concatenate(seq2)
I have implemented the insert and remove functions, the constructors and the copy constructors successfully. But am having trouble with the concatenate function. For starters I have the following error after compiling:
169 C:\Users\...\sequence.cpp 'class Sequence' has no member named 'conacatenate'
So I can't even check my code. Please help. I am pasting my entire code, the header and the cpp in two parts
Hi everyone, I just can't seem to find an explanation for using this "->" in code, in C++. I've migrated from Java and C#, and haven't seen this notation before. Basic example:
CMesh *pMesh = WorldObjects[i]->m_pMesh;
As best as I can tell, this is the C++ equivalent of C#'s
WorldObjects[i].m_pMesh;
. (as if to say that m_pMesh is a member variable, or method of the WorldObjects object, but as it is only a code snippet, I cant check the classes to see)
Just a quick syntactic explanation is all I need. Thanks.
Hello everyone, i'm porting an application from C# to C++, and i find the syntax and all that of C++ rather cumbersome (though C/C++ was my first language).
I have a very specific question, and another few more-or-less general ones.
The specific question:
In C#:
Bitmap image;
BitmapData ImageData;
ImageData=image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, image.PixelFormat);
byte* walker = (byte*)ImageData.Scan0;
//Sift through the bytes using a for
for(int i=0; i< image.Height*ImageData.Stride;i++)
{
string bit = Convert.ToString(*walker, 2);
//Get the byte represented by walker, by dereferencing it
//and convert the number (e.g. 235) to base 2, getting
//a string of 1's and 0's.
walker++;
//Increment the pointer
}
Easy enough, huh?
Here's the C++ version, where i'm having difficulties:
Bitmap^ image;
BitmapData^ ImageData;
ImageData=image->LockBits(Rectangle(0,0,image->Width,image->Height),ImageLockMode::ReadWrite,image->PixelFormat);
IntPtr walker=ImageData->Scan0;
for(int i=0; i<Image->Height * ImageData-> Stride; i++)
{
//1.How do i get the value at IntPtr?? Dereference does
//not work.
//2.How do i increment the pointer?
}
So my problems are, how do i increment IntPtr, and how do i get the value at its address (dereference) ?.
Thank you.
And now, general questions:
1. Why do i need to put the '^' sign when declaring stuff.
String^ myString;
2.How do i know when to use scope resolution operator :: or arrow sign -> ?
3.Why does this instruction:
Input a list of positive numbers, terminated by 0, into an array Numbers. Then, display the array and the largest and smallest number in it.
Process, Input, Output information with variable names and type and complete pseudo code of the program (with declaration of variables, calling of modules, any modules, inputs, outputs, etc.)
This is what is being asked and I dont have a clue what to do. Can someone please help me. I would really appreciate it..
I guess this is it correct?
int[] Numbers;
Numbers = new int[50];
int K;
int Flag;
int Count;
int OneNumber;
int Temp;
String UserInput;
System. Console. WriteLine ("This program will sort 50 positive numbers for you");
System, Console. WriteLine ("The Program will show all numbers from smallest to highest and then display the lowest and highest number in the Array.
System. Console. WriteLine ("Enter your first positive number or enter a 0 to exit. ")
UserInput = System. Console. ReadLine;
OneNumber = int.Parse (UserInput);
Count = 0;
While (OneNumber = 0)
Numbers [Count] = OneNumber;
Count = Count + 1;
System. Console. WriteLine ("Enter another positive number or enter a 0 to exit.");
UserInput = System. Console. ReadLine;
OneNumber = int.Parse (UserInput);
Flag = 0;
While (Flag= 0)
Flag = 1;
For (K = 0; K = (Count - 2); K++)
If (Numbers [K] < Numbers [K + 1]
Temp = Numbers [K];
Numbers [K] = Numbers [K + 1];
Numbers [K + 1] = Temp;
Flag = 0;
System. Console. WriteLine ("Sorted List of Numbers);
For (K = 0; K <= (Count - 1); K+)
System. Console. WriteLine (Numbers [K])
Problem: Write a class that defines a car. The car class stores the following data about a car: Member Name Data Type
make string
model string
vin string
owner string
doors int
mileage float
gas tank float
trip float
gas remaining float
Create methods to set data into the data members and to read the data from the data members. Write a method to determine the gas mileage.
What I got so far is:
#include <iostream>
#include <string>
using namespace std;
class car
{
private:
string make,
model,
vin,
owner;
int doors;
float mileage,
gasTank,
trip,
gasRemaining;
public:
string getMake();
string getModel();
string getOwner();
int getDoors();
float getMileage();
float getGasTank();
float getTrip();
float getGasRemaining();
double getGasMilease();
};
int main()
{
car cars;
cout << " Please enter Make of car: ";
cin >> cars.make;
return 0;
}
string car::getMake()
{
return make;
}
I am getting the following errors:
1>.\CH 7 Addendum 2 Car Class.cpp(41) : error C2248: 'car::make' : cannot access private member declared in class 'car'
1> .\CH 7 Addendum 2 Car Class.cpp(15) : see declaration of 'car::make'
1> .\CH 7 Addendum 2 Car Class.cpp(13) : see declaration of 'car'
This week we just started to learn about classes so I am totally lost even after reading the textbook several times and looking over their examples. Can anyone help me understand what I am doing wrong with the class?
cout << "how are you today? good, bad, or eh?" << endl;
cin >> who;
if (who == "good")
{
cout << "ahh thats pretty cool i guess..." << endl;
}
if (who == "bad")
{
cout << "LOL that sucks for you!!!!" << endl;
}
if (who == "eh")
{
cout << "EHHHHHHHHHHHHH!!!" << endl;
}
else
{
cout << "i dont know what that means? close and retry please..." << endl;
}
cout << "god im so bored" << endl;
cout << endl;
system("pause")
return 0;
}
i get an error :
ISO C++ forbids comparision between pointer and integer
how do i fix this? and what is actually causing this and why is it like that?
also im just starting out in codeing and wanted to know if there was a way i can make it so i can run it in anything besides CMD.
like if i could make it so when someone clicks on it , it opens up in like a window that i choose or something then it has buttons where it has the different types of code i put in there...
Hello guys, that's my first post around here and I have a problem with binary files.
I'm writing a simple editor for my arkanoid clone game. This editor opens a binary file defined by this:
0-26 byte: Descriptor for the file. Once in each file.
27->(1141*n): Levels inside the file, each level has 1141 bytes.
Here starts my problems! The game and the editor use the "Files" class, which manipulates the stream, just loading and saving levels, if in editor. Everything works fine in editor but only if i have at least a blank level file!
The game of course can't continue if there are no file levels, but the editor needs to create one, and it can't!
I need to:
- Binary file;
- Open the file to write anywhere in it without losing previous content (eg: The user may have a file with 30 levels, but want to change level 2, so not just appending);
- Creating the file if it doesn't exist (eg: User deleted the file completely or it got corrupted, which is checked elsewhere); and
- Having only one file open all time (Maybe my error is here, don't know if this is good practice or not).
This is outside the constructor, the game and editor call a load default level function containing this code, and the destructor closes the file.
What I already tried:
- Playing with the open modes:
//Recreates file everytime
file.open(filename.c_str(), std::ios::in | std::ios::out | std::ios::binary);
//Can't access beginning of file; Any seek(0) returns the pointer to the end of file (after last byte)
file.open(filename.c_str(), std::ios::in | std::ios::out | std::ios::app | std::ios::binary);
- Think to create a temp file only for output -> open the levels file in input only -> copy level to temp file -> close levels file -> reopen it in output mode (erased all content) -> Copy temp file back to level file -> close temp file. Seems to much trouble, but if it's the only way...
- Trying to seek backwards with negative values (eg:
seekp(-(levelSize), std::ios::cur)
) but it doesn't seem to work since it always goes forth!
Please guys, help me! I can post other parts of my code if you think it's relevant!
I'm writing a c++ code that reads a wav file and stores read values to a 1D array of integers. After doing some manipulation, I am able to write the values of the array to a new output wav. I use libsndfile library to do the reading and writing (sf_read & sf_write).
I then play this output wav by using Audiere library. I know the manipulation works since the sound played is the one I expect.
My question is how can I play the contents of the array without having to write it to secondary storage just to have it read again?
------ Build started: Project: engine, Configuration: Debug Win32 ------
Compiling...
baseanimating.cpp
c:\program files\microsoft visual studio 9.0\vc\include\time.h(39) : error C2143: syntax error : missing ';' before 'string'
c:\program files\microsoft visual studio 9.0\vc\include\time.h(39) : error C2059: syntax error : 'string'
c:\program files\microsoft visual studio 9.0\vc\include\time.h(39) : error C2143: syntax error : missing ';' before '{'
c:\program files\microsoft visual studio 9.0\vc\include\time.h(39) : error C2447: '{' : missing function header (old-style formal list?)
c:\program files\microsoft visual studio 9.0\vc\include\ctime(19) : error C2039: 'clock_t' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(19) : error C2873: 'clock_t' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(21) : error C2039: 'asctime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(21) : error C2873: 'asctime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(21) : error C2039: 'clock' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(21) : error C2873: 'clock' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(21) : error C2039: 'ctime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(21) : error C2873: 'ctime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(22) : error C2039: 'difftime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(22) : error C2873: 'difftime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(22) : error C2039: 'gmtime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(22) : error C2873: 'gmtime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(22) : error C2039: 'localtime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(22) : error C2873: 'localtime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(23) : error C2039: 'mktime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(23) : error C2873: 'mktime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(23) : error C2039: 'strftime' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(23) : error C2873: 'strftime' : symbol cannot be used in a using-declaration
c:\program files\microsoft visual studio 9.0\vc\include\ctime(23) : error C2039: 'time' : is not a member of '`global namespace''
c:\program files\microsoft visual studio 9.0\vc\include\ctime(23) : error C2873: 'time' : symbol cannot be used in a using-declaration
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(7) : error C2146: syntax error : missing ';' before identifier 'counter'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(11) : error C2061: syntax error : identifier 'clock_t'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(9) : error C2614: 'CTimer' : illegal member initialization: 'counter' is not a base or member
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(13) : error C2065: 'clock_t' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(13) : error C2146: syntax error : missing ';' before identifier 'tick'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(13) : error C2065: 'tick' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(13) : error C2039: 'clock' : is not a member of 'std'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(13) : error C3861: 'clock': identifier not found
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(15) : error C2065: 'tick' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(15) : error C2065: 'counter' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(15) : error C2065: 'ms' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(17) : error C2065: 'counter' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\timer.h(17) : error C2065: 'tick' : undeclared identifier
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseanimating.cpp(28) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseanimating.cpp(39) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseanimating.cpp(50) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseanimating.cpp(61) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseanimating.cpp(72) : warning C4018: '<' : signed/unsigned mismatch
Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\engine\engine\Debug\BuildLog.htm"
engine - 39 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The only file that is mine out of those errors is time.h:
#ifndef TIMER_H
#define TIMER_H
#include <ctime>
class CTimer {
clock_t counter;
public:
CTimer(): counter(0) {}
Ok so ive been writing code for a web server to return requested files, It works well for html and txt files but when an image is requested all i recieve is the url of the file... In firefox in conqueror i dont get anything. All i do is read the file and send it that is all so that part is fine. I think the problem is somewhere in the headers of the response of the server.
Hi, I'm working through the 3rd chapter of Thinking in C++ Vol 1 by Bruce Eckel (free online). I am using Code::Blocks as my IDE. I've try searching for this problem through the forum but haven't found a solution; I think it might be a IDE-specific problem.
The undefined reference error pops up when I try to compile Bitwise.cpp, which references printBinary.h which uses a function in printBinary.cpp. All 3 files are located in the same directory (in a folder called "C++" in My Documents).
The error message says "undefined reference to 'printBinary(unsigned char)'
For your convenience, I have pasted the code below:
//: C03:printBinary.h
// Display a byte in binary
void printBinary(const unsigned char val);
///:~
//: C03:Bitwise.cpp
//{L} printBinary
// Demonstration of bit manipulation
#include "printBinary.h"
#include <iostream>
using namespace std;
// A macro to save typing:
#define PR(STR, EXPR) \
cout << STR; printBinary(EXPR); cout << endl;
int main() {
unsigned int getval;
unsigned char a, b;
cout << "Enter a number between 0 and 255: ";
cin >> getval; a = getval;
PR("a in binary: ", a);
cout << "Enter a number between 0 and 255: ";
cin >> getval; b = getval;
PR("b in binary: ", b);
PR("a | b = ", a | b);
PR("a & b = ", a & b);
PR("a ^ b = ", a ^ b);
PR("~a = ", ~a);
PR("~b = ", ~b);
// An interesting bit pattern:
unsigned char c = 0x5A;
PR("c in binary: ", c);
a |= c;
PR("a |= c; a = ", a);
b &= c;
PR("b &= c; b = ", b);
b ^= a;
PR("b ^= a; b = ", b);
} ///:~
In the code below, I check if test.dll has been loaded, and it always returns false... I can't figure out what I'm doing wrong. Can anyone give me a hand?
P.S.: I've triple checked that the DLL is in the running directory.
#include <iostream>
#include <windows.h>
typedef int (*AddFunc)(int,int);
typedef void (*FunctionFunc)();
NOTE:
~this code is in c++
~you need not change anything in the code
~the commented lines are there just in case you want to see how the program works in real time - simply uncomment them and run the program, these commented lines are not necessary for the program to work
~code does not swap the characters of the string n times just to randomize
~string contents are shuffled character by character only
~the code is done with Code::Blocks
HOW THE CODE WORKS:
~the program asks user to input a string, then it outputs the shuffled version of the string
1. the program tells the user to enter a string
2. getline(cin,word); saves the string into string variable word
3. the length of the string is determined and saved to int variable x
4. srand is called so that the program will randomize differently for each instance you run the program
5. the while loop does the assigning of characters found in string variable word to temp
6. the resulting string temp is outputted so you can see the result of the shuffle
~further explanation for number 5
for example, you entered "twister"
twister is saved to string variable word
x is given the value of the length of the string variable word, which in this example, is 7 (seven)
in the loop,
temp is the string where we add characters found in string variable word. the character that we will use and copy to temp is determined by the int variable y, which generates a value from 0(zero) to the length of the string variable minus one, which in this instance, is 6. after choosing the character, the character is appended to temp.
the problem now is, we dont want that same character to be used again/selected by the randomized selector y - this problem is solved by the other lines in our program.
the idea is, we remove that chosen character (after appending it to temp) from the original string word, so it would not be chosen again.
we can remove that character by:
1.) cutting the string into three, first part will be from the start of the string to the character before the chosen character, second part will be the chosen character, then the last part will be after the chosen character to the last of the string... after cutting it and saving the first and third(last) parts to new strings, we fuse them into one....or
2.) simply assigning the last character of the string into the place of the chosen character (which will overwrite and delete the chosen character) , then cutting the string from the beginning up to the second-to-the-last part of the string (which will delete the last character of the string - which is okay since we moved it to the chosen character's place already)
after that, you see, we don't have the chosen character anymore, we have the last character of the string on it, and the length of the string decreased by one.
the loop then continues until all of the characters from string variable word is gone.
INPUT RESTRICTIONS:
~actually from what i tested, there are no restrictions for the program input...
~it even accepts strings with spaces
~there are no restrictions for values of the string variable word too.
uhm i think thats all about the code. i don't really know if this kind of code exists some place else other than this post because all i see are either random swapping shufflers or threads that needs help on shuffling. and just so you know, it is me who made this code, so yes its my mistake if ever there is one in the code.
I have a Panel that holds 200 buttoncontrols. If I for example minimize the Formwindow and maximize the window again,
panel1 that holds the 200 buttoncontrols makes the 200 buttoncontrols to "flicker" for about 2 seconds.
I beleive I have set up code for panel1 that have Doublebuffer = true; (I run this on computer: 2.2 Ghz Dual core)
I dont know how to make this work correctly because the whole application really flickers all the time ?
Below I have put all declarations that has with panel1 to do to see if it is possible to find the problem.
//panel1 declaration
public ref class DoubleBufferPanel : public Panel
{
public: DoubleBufferPanel(void)
{
this->SetStyle(ControlStyles::DoubleBuffer |
ControlStyles::UserPaint |
ControlStyles::AllPaintingInWmPaint, true);
this->SetStyle(ControlStyles::DoubleBuffer, true);
this->UpdateStyles();
}
};
//private: System::Windows::Forms::Panel^ panel1;
DoubleBufferPanel^ panel1; //Exchange above line to this line ?
//this->panel1 = (gcnew System::Windows::Forms::Panel());
panel1 = gcnew DoubleBufferPanel(); //Exchange above line to this line ?
this->panel1->SuspendLayout();
I have recently installed Code:Blocks 8.02 for Windows, but I have a problem with my debugger. Every time I try to debug I get an error that says I haven't set my debugger executable yet.
I selected the mingw c++ compiler included in the install, and set the debugger exe to the gdb.exe from bin.
I'm writing a manager class that should handle a vast and expandable group of classes. The manager class uses a hash_map to store all these etherogenous objects. The objects are all derivations of a base class Object, and of different "interface" classes which are used to define required functions. An example:
class Object{ ... };
class IUpdatable
{
...
public:
virtual void Update()=0;
...
};
So I could have classes that derive from class Object and from class IUpdatable, but that override the Update function in very different ways - or that do not even derive from IUpdatable (meaning that particular type of object requires no update at all after creation).
Now, I can't change this design. So, first I thought to just fill the hash map with pointers to Object, and (continuing with the example above) within the manager Update method, let the polymorphism kick in once I call the Update function of the updatable stored objects, like this:
void Update()
{
// SHM is the hash map type, s is the hash map instance
for (SHM::iterator i=s.begin(); i != s.end(); ++i)
{
i->second->Update();
}
}
But obviously I can't do that, since
1. I do not know if the stored object derives from IUpdatable too.
2. Update is not a member of Object (and it makes no sense to have Update defined in Object).
I was thinking that I could just use typeid and confront the type info with all the possible types that derive from that "interface" class, but that's ugly programming imho. Maybe it's possible to check if a class implements a function (and in that case I'd automatically be allowed to cast the object to the IUpdatable type and use polymorphism).
So my question is, is there an elegant way to solve this situation?
hi
as i finished my I sem of computer applications at SGRRITS coll in dehradun ,india in second sem C++ is part of my course.
now i want to know about the main difference between c and c++
how c++ is more use ful and its features with the help of example.
please also explain in brief how above example will executed.
i am a begnner so please....................you know.
I am making a scientific calculator as an assignment in my class. I am using switch case for all the operators like +-*/ , and I am calling them with a single keyword like '+' for addition and so on. The problem is that when i try to use more than one word in case statement for mathematical function like Tan, Cos or sin , The program does not calculate anything. I am using char for the cases in switch statement.
here's da snippet of what i am doing (i am showing some part of the program, consider i have already declared all the variables) :
char ch[10];
switch(ch)
{case 's': // i want to use 'sin' here but the program does not calculate anything after i do so!
trig= sin(fno*pi/180);
cout<<endl<<"Sin("<<fno<<") = "<<trig<<endl<<endl;
break;
}
I have been having a lot of trouble getting my overloaded operators to properly with each other, especially in cases such as a=a+b+c
When I execute the program, I get an error: "Unhandled exception at 0x01201f10 in Project1_v3.exe: 0xC0000005: Access violation reading location 0xcccccccc." But I am not sure exactly what that means or where it comes from.
I have posted all relevant code including my test file. I would really appreciate any insights you have about what could be causing this problem.
Implementation file:
#include "matrix.h"
//Constructors
matrix::matrix(int r, int c)
//create matrix with specified row and column dimensions
{
try
{
if ((r<=0)||(c<=0))
throw invalid_argument ("Matrix row and column arguments must be greater than zero.");
row=r;
column=c;
}
catch (exception & ex)
{
cout<<"Error: "<<ex.what()<<endl;
}
if ( a != b )
{
cout << "Matrix a and b are not equal" << endl;
cout << "a = " << a << endl;
cout << "b = " << b << endl;
};
e += f;
cout << "f = " << f << endl;
cout << "e -= f = " << e << endl;
f = e = d;
h = d + e + f; //error.
cout << "d = " << d << endl;
cout << "e = " << e << endl;
cout << "f = " << f << endl;
cout << "h = " << h << endl;
if ( h == e ) cout << "Matrix h and e are the same" << endl;
else
{
cout << "Matrix h and e are not equal" << endl;
cout << "h = " << h << endl;
cout << "e = " << e << endl;
}
Hello. Can someone tell me what will happen if i have an array Ar[5][5] and a pointer ptr = Ar[0][0] and try accessing the second line of Ar throught ptr by increasing it by 5? I mean ptr+5 ==Ar[1][5] or something else?
int count = 0;
int random_num = (rand () % 100) + 1;
int high_num = random_num;
int low_num = random_num;
float total = 0.0;
while (count < 100000){
count++;
random_num = (rand () % 100) + 1;
if (high_num < random_num)
high_num = random_num;
if (low_num > random_num)
low_num = random_num;
total = total + random_num;
}
float average = total / 100000;
cout << "The high number is: " << high_num << endl;
cout << "The low number is: " << low_num << endl;
cout << "The average is: " << average << endl;
system ("Pause");
return 0;
}
The program compiles and runs. It generates random numbers, displays the highest and lowest, and the average. I got it to get the highest and lowest numbers by fiddling around with the "if" statement and using the ">" and "<" signs.
Eventually I got it to work after trying combination of numbers and declared int statements and was able to get it to define the high and low numbers correctly.
My question is, how does it work?
if (high_num < random_num)
high_num = random_num;
if (low_num > random_num)
low_num = random_num;
I set them to equal to the random number, which I defined later in my int statements. In the "if" statements, it shows the high number being less than a random number, and if it's true, the high number is equal to a random number.... I just don't get how it'd work. Wouldn't it be a greater than sign, which I've tried. All it does is make the lowest 100 and the highest 0.
Ohkay now I'm rambling. Could someone just tell me how that statement works
need to change this from availcredit01.cpp to availseats01.cpp and make the necessary adjustments
1)ask user to enter the room size
2)get room size
3)ask user to enter number of students
4)get enrolled
5)set avilseats to room size minus enrolled
6)display the available sets
7)halt and return to operating system
i'm a newb so any help would be greatly appreciated
#include <iostream> // systems-supplied hdrs
#include <cstdio> // scanf and printf
using namespace std; // avoid std::cin ...
int main (void) // main returns an int
{
/* main local space */
double balance; // input variables
double creditLimit; //
double availCredit; // output variable
/* begin procedural code */
cout << "Enter balance: "; // prompt user
cin >> balance; // get data
cout << "Enter credit limit: "; // prompt user
cin >> creditLimit; // get data
when i run my code, i get lots of undefined class errors, even though i have defined and included the files properly(i think).
here are the errors i'm getting:
------ Build started: Project: engine, Configuration: Debug Win32 ------
Compiling...
baseentity.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(13) : error C2079: 'CGlobals::controller' uses undefined class 'CEntityController'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(9) : error C2228: left of '.AddEntity' must have class/struct/union
type is 'int'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(59) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\baseentity.cpp(60) : warning C4244: 'argument' : conversion from 'double' to 'float', possible loss of data
main.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(13) : error C2079: 'CGlobals::controller' uses undefined class 'CEntityController'
entitycontroller.cpp
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\globals.h(13) : error C2079: 'CGlobals::controller' uses undefined class 'CEntityController'
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(7) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(13) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(19) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(28) : warning C4018: '<' : signed/unsigned mismatch
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(45) : warning C4244: 'argument' : conversion from 'double' to 'clock_t', possible loss of data
c:\documents and settings\tom\my documents\visual studio 2008\projects\engine\engine\entitycontroller.cpp(46) : warning C4305: '+=' : truncation from 'double' to 'float'
Generating Code...
Build log was saved at "file://c:\Documents and Settings\tom\My Documents\Visual Studio 2008\Projects\engine\engine\Debug\BuildLog.htm"
engine - 4 error(s), 8 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I've been trying to fix this error for a while now, I could really use some help.
C:\Users\Clayton\Documents\CH4P11.CPP(71) : error C2676: binary '>>' : 'class std::basic_ostream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acceptable to the predefined operator
#include <iostream>
#include <iomanip>
using namespace std;
Hi All,
When I try to compile the code below, I get error message " error: ‘MAX_IMG_HEIGHT’ undeclared here (not in a function)". I tried to declare them in different ways but it does not work. Does anyone have idea ?
I appreciate for helps,
The code is:
/* ImagExper.h
- miscellaneous structure header file for ImagExpert software package */
/* image processing range deifnition */
#define top_left_x 20
#define top_left_y 280
#define bottom_right_x 460
#define bottom_right_y 500
/* edge element gradient magnititue and direction */
//extern const int MAX_IMG_HEIGHT;
//extern const int MAX_IMG_WIDTH;
Hello, I'm not much of a programmer and will probably never be, but am just curious.
Can I initialize a pointer with a constant value different than NULL? I.e. can I tell my pointer to point at one particular memory cell? It's a number so why couldn't I? I know it would be of little use in normal programming, but I thought it could be could good while programming some devices with very little memory, where one would like to control every cell.
hi can some one help me
I want to take url name in textbox from user and when he press enter key that url should open.
I want code of this program in c++ visual studio 2008.
{
cout << "Please enter an corresponding letter." << endl;
}
else
cout << "You have chosen" << symb << endl;
cin >> symb1;
cin >> symb2;
cin >> symb3;
cin >> symb4;
cout << "You have a total of 30 dollars.\n";
cin >> tot_mon;
tot_mon = 30;
cout << "Please pick a letter that corresponds with the merchandice of your choosing.\n";\
Hi i'm writing this program where the user chooses whether to print out a square, a forward triangle, and a backwards triangle using the "*" character. I got the square and the backwards triangle to work and the forward triangle, but i cant figure out how to do the back wards one.
*
**
***
**** is how the foward triangle looks when the user enters the size of 4 the backwards one should look like
*
**
***
**** when the user enters 4 for the size. my code for the normal triangle is below(for some reason this wont show up how its suppose to but it should look the same as the normal triangle just slanting to the left instead of to the right.)
cout << "enter the size of your triangle." << endl;
cin >> size;
Hello. I need an example of how to pass an array of pointers to objects as a parameter to a function or a constructor. It's urgent. Please help me. Thank you.
I am having problems with the new operator() specifically within
std::string
I appear to have hit a memory limit in visual studio.
Ideally I would like someone to help me find one of the following solutions:
1 - Can I access the memory in a very big file directly without a memory buffer?
2 - How do you increase the maximum size of the free store in visual studio?
My approach at the moment is not working I have a very big file that I want to
chop before processing.
- I create a membuffer for a 1Gb file (this was made from 25Gb file)
- then try to use a std::string to iterate over the string.
but I cannnot create the string as I get
bad allocation error
from cstr()
std::ifstream fin("D:\\Gig1.txt", std::ios::in);
if(fin.is_open)
{
unsigned int sz(1073741825); // 1 gig (1024)^3
char * memblock = new char[sz]; //this is fine
//check file sz is right size not called as sz == gcount
fin.seekg(0, std::ios::beg);
fin.read(memblock, sz);
if(sz > fin.gcount())
{
sz = fin.gcount();
}
try
{
std::string str(memblock, sz); //too much for visio :(
}
catch(exception &e)
{
std::cout << e.what() << std::endl;
}
delete [] memblock;
fin.close();
}
}
This is an approximate code and I am posting here as my first post was asking the wrong question.
int main(void){
//It finds an error here
int x, 5, 7, 2, total;
printf("Hello. This program will evaluate the expression 5(x+7)-2. \nEnter the value for x:");
//And here
total= 5(x+7)-2;
cin >> x;
cout << total << endl;
getchar();
return 0;}
I know it contains many errors; can someone tell me what I should do?
Thanks a lot!!!
2008 scandalz.net
They told me you had proven it When they discovered our results
About a month before. Their hair began to curl
The proof was valid, more or less Instead of understanding it
But rather less than more. We'd run the thing through PRL.
He sent them word that we would try Don't tell a soul about all this
To pass where they had failed For it must ever be
And after we were done, to them A secret, kept from all the rest
The new proof would be mailed. Between yourself and me.
My notion was to start again
Ignoring all they'd done
We quickly turned it into code
To see if it would run.