C++ :: How To Make Map Return Null When There Is Nothing At Certain Position
May 7, 2015
Code:
std::map<int, DWORD> unitColors;
DWORD color = unitColors.at(unit->id);
I want to use a color value of 0x00000000 when
a DWORD at unit->id of unitColors is unavailable.
Is it possible?
View 14 Replies
ADVERTISEMENT
Jan 10, 2015
Here's my code
bitIndex = 5;
Code:
bool getBS(PBitSet _this, int bitIndex) {
if(_this->bits & (1 >> bitIndex))
return true;
else
return false;}
I want this code to return the value of the bit at position bitIndex. It can be either false or true. The problem is, that it always returns false, even thought I enter 16 as my number, so the 5th bit should be true.
0000|0000 = 0
0001|0000 = 16
View 10 Replies
View Related
Sep 27, 2013
What is the command to return the position of the mouse on screen in C?
View 8 Replies
View Related
Mar 4, 2013
What I have to do is write a small program in C++ to parse the symbols that are used on 5 different lines of text in each position until position 30 is reached on each line. The goal of the parsing program is to interpret the symbols (characters), if there are any per each position, on the 5 lines of text in order to output the actual data that the group of symbols represents.
My question for is this: Is there anything special from a C++ environment that should go in to something like this outside of using standard stuff like the math associated with the search algorithm that has to happen here? The symbols are located in a file, so I know I have to include "iostream" and a few other headers. But outside of header inclusions and the code necessary to iterate and streamline the search and interpretation process, am I missing anything special that I couldn't otherwise find through simple google searches?
View 6 Replies
View Related
Mar 25, 2014
I have a class called items and stored in a vector as vector<items*> item.now I want to make a function to return the placement # that the item is stored at with a unsigned int. but if I don't find the item is there like a null unsigned int that can be returned.
unsigned int someFunc(vector<items*> item)
{
unsigned int size = item.size();
for (unsigned int i = 0; i < size; ++i)
{
if (item[i]->getItemName() == "sword")
{
return i;
}
}
//i need code here incase the item is not there
}
because the item might not be there and i would like to do a line if(unsigned int) do this code
View 19 Replies
View Related
Feb 18, 2014
I am looking at one of the functions of an exercise:
void escape(char * s, char * t) {
int i, j;
i = j = 0;
while ( t[i] ) {
/* Translate the special character, if we have one */
switch( t[i] ) {
[code]...
Notice the while loop evaluates the current value in t to true or false. When we hit the null terminator, does that get evaluated as 0 and hence evaluates as a falsy value so the while loop exits?
View 1 Replies
View Related
Mar 31, 2015
When you login to my site my loginservice which is done by ajax and json make a session called context.Session["Name"]. With BreakPoints it shows that everything is good and the variables are in place. However when I use Session["Name"] it comes out as null.
I will add my code at the bottem not
using System;
using System.Collections.Generic;
using System.Linq;
[Code].....
View 2 Replies
View Related
Aug 17, 2014
how to make subroutines and return multiple arrays.Before that, i wrote my program on matlab. could my program to be structured as following?
<header>
initial value of program;
subroutine1() {
calculating the first work;
return 2 or 3 arrays;
[code].....
View 14 Replies
View Related
Mar 29, 2013
I'm writing some functions pertaining to binary trees. I've used recursion once before while learning quicksort but am still quite new and unfamiliar with it. And this is my first time touching a binary tree. So my question: In my addnode function, will the return root statement at the end ever return a value other than the value passed to the function?
Code:
#include <stdlib.h>
struct tnode
{
int data;
struct tnode * left;
struct tnode * right;
}
[code]....
View 4 Replies
View Related
Jan 11, 2015
From the page: [URL] ....
#include <iostream>
using namespace std;
int n;
int& test();
[Code] ....
Explanation
In program above, the return type of function test() is int&. Hence this function returns by reference. The return statement is return n; but unlike return by value. This statement doesn't return value of n, instead it returns variable n itself.
Then the variable n is assigned to the left side of code test() = 5; and value of n is displayed.
I don't quite understand the bold sentence. Shouldn't value of n and variable n be the same?
View 8 Replies
View Related
Sep 21, 2013
I have a "fairly" large, std::map. Is there a way, to get the key of an element, by position? E.g., something like,
map.at(i).getkey
View 5 Replies
View Related
Oct 15, 2014
For some reason I keep getting null pointers in most of my functions, and in my convertTime function the numbers are way higher than they should be.
Code:
//Utils.H header file----------------------------------------------
//This function takes the radius of a circle and returns the diameter, the circumference and the area.
int circleStatistics(double radius, double *diameter, double *circumference, double *area);
//This function takes a number of days and returns how many years, weeks and remaining days that is.
int convertTime(int days, int *y, int *w, int *d);
//This function takes a length of time and calculates the dilation of that time at a percentage of the speed of light.
int lorentzTimeDilation(double normalTime, double percentC, double *dilatedTime);
[Code] ....
View 3 Replies
View Related
Apr 13, 2014
Is:
char *endp = NULL;
the same thing as:
char *endp = 0;
?
View 1 Replies
View Related
Jul 23, 2013
I am beginner in C++ programming. And i was try use STRTOK code with NULL fields, but in ARRAY fields NULL values is skiped. For example:
input text in Memo2:
AnsiString PAT02[100][20];
for (int IndexVRadku02 = 0; IndexVRadku02 < Memo2->Lines->Count ; IndexVRadku02++) {
AnsiString PNF02 = Memo2->Lines->Strings[IndexVRadku02];
char * PN02;
[Code] ....
Result:
Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6
But i need this result:
Array 00 01 02 03 04 05
00 0000 TEXT1 TEXT2
01 0002 TEXT3 TEXT4 TEXT5
02 0003 TEXT6
View 2 Replies
View Related
Jul 9, 2014
I dont see any point of NULL in cstring. The code given below just outputs same as it would have done with NULL. My understanding is if size of char array is less than length of char array then null must be manually added?
#include <iostream>
using namespace std;
int main(){
char chr[0];
cin>>chr;//or if you use cin.getline;
cout<<chr<<endl;
return 0;
}
Enter something: hellowwwww
hellowwwww
Segmentation fault (core dumped)
why? for NULL char or something else?
View 1 Replies
View Related
Apr 9, 2014
In my raytracer-project I have the following function:
bool hitObjects(Ray &ray, std::vector<Object *> &objects, Vector3& normal, Material *mat) {
double tmin = K_HUGE_VALUE;
double t;
[Code]....
When I try to run this, I only get the message "Material pointer is null". So, somehow the pointer is null after the hitObjects-function is called, even though it isn't inside that function.
View 6 Replies
View Related
Jul 30, 2014
The resultset is always null and the connection is alive. The VS2013 debugger says that mysqlcppconn.dll has no debugging symbols. Tested the query on a mysql console and it worked fine, it returned 1.
CDatabase::CDatabase(CSettings* settings) {
settings = settings;
try {
Connection* con = get_driver_instance()->connect("", "", "");
con->setSchema("hyperbot");
cout << "Connected." << endl << endl;
[Code] .....
I also get these strange warnings on compile:
1>c:program files (x86)mysqlmysql connector c++ 1.1.3includecppconnsqlstring.h(38):
warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'
needs to have dll-interface to be used by clients of class 'sql::SQLString'
[Code] ......
View 10 Replies
View Related
Mar 1, 2015
I'm playing around with parts of code and am coming across some errors. Most of my concern is related to strtok(). I've used it before but with a char* named token. I used a while loop to continuously check whether token was equal to NULL. In the following code, however, there aren't any checks. I was wondering if that is why this code prints (null) while running. Also, I would like to know if it is possible to read input like this code attempts to do - assigning tokens to each variable one after the other.
The format of the input:
Zucchini, Squash, pound
Yellow, Squash, pound
Tomatoes, Ugly Ripe, each
#include <stdio.h>
#include <stdlib.h>
[code]....
View 3 Replies
View Related
May 17, 2014
So I'm writing a small program for class, and for some reason I keep getting an error when trying to initialize head to NULL. Even threw in the namespace just to see, nothin'.
#ifndef NUMBERLIST_H
#define NUMBERLIST_H
using namespace std;
[Code].....
There's my header file. Not sure what I'm doing wrong with the constructor.
EDIT: Got it to work with nullptr, but still curious why that isn't working
View 2 Replies
View Related
Apr 13, 2015
I am trying to query fields in a where clause using LINQ to SQL and for some reason I cannot figure out why it doesn't work:
var qryGetMonsterID = (from students in dbContext.tblStudentPersonals
where (students.givenname.Equals(fn)) && (students.familyname.Equals(ln)) && (students.middlename.Equals(mn)) && (students.email.Equals(e))
select students);
The returned SQL Syntax is:
SELECT [t0].[monsterid], [t0].[givenname], [t0].[middlename], [t0].[familyname], [t0].[homeaddress], [t0].[city], [t0].[state], [t0].[postal], [t0].[primaryphone], [t0].[secondaryphone], [t0].[email], [t0].[username], [t0].[lastmodified], [t0].[modifiedby]
FROM [dbo].[tblStudentPersonal] AS [t0]
WHERE ([t0].[givenname] = @p0) AND ([t0].[familyname] = @p1) AND ([t0].[middlename] = @p2) AND ([t0].[email] = @p3)
Not sure but the values for middle name could be null - because not everyone has a middle name and the same is true for e-mail.
View 6 Replies
View Related
Jun 28, 2014
I have a datagridview (dgv) that is bound to database:
QtyOnHand QtyOnHold QtySold QtyAvailable
10 2 1 null
12 null null null
null null null null
7 5 null null
25 null 5 null
I want to iterate through the datagridview and calculate the last column with this formula:
QtyAvailable = QtyOnHand - QtyOnHold - QtySold
so the datagridview should become:
QtyOnHand QtyOnHold QtySold QtyAvailable
10 2 1 7
12 null null 12
null null null null
7 5 null 2
25 null 5 20
I use this code:
foreach (DataGridViewRow row in dgv.Rows){
if (string.IsNullOrEmpty(row.Cells["QtyOnHand"].Value.ToString())){
row.Cells["QtyAvailable"].Value =
Convert.ToInt32(row.Cells["QtyOnHand"].Value) -
Convert.ToInt32(row.Cells["QtyOnHold"].Value) -
Convert.ToInt32(row.Cells["QtySold"].Value) -
Convert.ToInt32(row.Cells["QtyAvailable"].Value);
}
}
The problem is when any of the value on the right side of the equation is null, the whole equation is invalid. I need to replace the null values by 0 on the fly so that it can be calculated. Note that I do not want to actually replace the null values in the second and third columns of the table, just replace it in the equation whenever it applies to make the calculation work.
View 4 Replies
View Related
Dec 24, 2013
So for a project I'm working on, I'm using an array and generating it's values randomly but unique. Currently I'm working on a 3X3 array and the generated values are in the range from 1-9. So I wrote a function that will tell me the position of the cell whose value is 9. This is the function I wrote:
Code: void Llogaritje1(int t[3][3],int &i, int &j){
int y,l;
for(y=0;y<3;y++){
for(l=0;l<3;l++){
if(t[y][l]==9){
i=y;
j=l;
break;
}
}if(t[y][l]==9) break;
}
}
But it doesn't work on all cells. Seems like at cells t[1][0] and t[2][0] the values that i and j take are 0 0 since when I print them after excecuting the function that's what it returns. I really don't understand why.
View 4 Replies
View Related
Jan 25, 2013
I want to get the iterator position after to use find if:
std::list<Texture*>::iterator result = find_if(
texturelist.begin(),
texturelist.end(),
std::bind2nd<CompareTEX>(CompareTEX(),n_tex));
if (result != texturelist.end()) {
return // position result
}
View 5 Replies
View Related
Mar 14, 2013
I have a string like:
char *origin = "THIS, IS, SPARTA!"
What I want to do is get all characters in a string up to a certain delimiter, for that I've searched I can do that with:
sscanf
getline
strok
But what I don't know and haven't found is how to use these functions but to start reading from a certain position in the string. So I need to get the characters up to a comma but after "THIS," so that would be starting in position 5...
How could I do that? I tried using [x] in brackets but then it would just read a character...
View 5 Replies
View Related
Feb 26, 2013
I am new to grpahics progamming in/under Borland C. I have included the "graphics.h" header file but i am unable to take input on the screen. If I try to move my cursor to a specified position using gotoxy() function the pointer doesnt moves to the specified location and starts taking input at (1,1) coordinate.
View 1 Replies
View Related
Jun 4, 2014
I need to keep a data structure, which has an id, an object pointer and a position. this id is used to randomize things, the object and the position is attached to this id. So which way is better?
Code:
struct data {
int id;
ObjectBase* obj;
Vector3 position;
};
vector<data> vecData;
or
map<int, pair<ObjectBase *, Vector3>> mapData;
View 4 Replies
View Related