C++ ::  How To Pass A String Variable To Message Box

Feb 20, 2013

I am having trouble finding the solution to printing the contents of a variable. Here is my code:

void OnSize(HWND hwnd, UINT flag, int width, int height) {
std::wstringstream ss (std::wstringstream::in | std::wstringstream::out);
ss << flag;
std::wstring myStr = ss.str();
MessageBoxW(hwnd,myStr, L"Window Resized",NULL);
}

Note, I have #defined UNICODE at the beginning. The compiler tells me this for myStr.

std::wstring myStr

Error: No suitible conversion function from "std::wstring" to "LPCWSTR" exits

View 2 Replies


ADVERTISEMENT

C++ :: Creating Variable On Runtime - Message Decoding

Apr 10, 2013

I receive messages over a bus. Suppose there is a function to read the messages storing them into a struct defined as follows:

typedef struct
{
ULONG timestamp;
BYTE ID;
BYTE data_length;
BYTE data[8];
} MSG_FRAME;

Depending on the message ID different messages represent different values for one project.For example msg with ID 10 can include in the 8 bytes something like:

width: 6 bits
height: 6 bits
actpos: 12 bits
maxpos: 12 bits
minpos: 12 bits
range: 16 bits
total: 64 bits = 8 bytes

Printing the message is no big deal. But here comes the tricky part. I want to print out the specific information hidden in the 8 bytes. I can define the structures for every msg ID and compile the program with this "special" header file, but I want to do it during runtime of the program, loading the information regarding the msgs, because i can have different projects where the information for different msg IDs can differ.

I've a non-C file, where basically all the information is written. Lets stay frame named

GetStatus{
bit 0 - 7 width
bit 8 - 15 height
.
.
}
etc.

How to read it on runtime and decode the messages? On runtime I'm not able to create variables and structures anymore!

View 13 Replies View Related

C++ :: Program To Display Error Message If Variable Entered Not An Integer

Nov 8, 2013

I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:

cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {

[Code] ....

I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.

View 8 Replies View Related

C++ ::  How To Pass Variable To A Function In Constructor

Jun 11, 2014

In a project I am working on, I have to initialize a window and pass it as a parameter to another constructor, but before the window is initialized, it is passed as a parameter thus causing an error. Here is some code :

Game::Game()
: mWindow(sf::VideoMode(640, 480), "SFML Application", sf::Style::Close)
, mWorld(mWindow) //<---- right here is where the mWindow variable needs to be passed
{
//...
}

Is there a way to make this work???

View 2 Replies View Related

C++ :: Pass By Value And Results By Variable Program

Jun 7, 2014

The instructions: A nutritionist who works for a fitness club facilitate members by evaluating their diets.As part of her evaluation, she asks members for the number of fat grams and carbohydrate grams that they consume in a day. Then, she calculates the number of calories that results from the fat using the following formula:

Calories from fat = fat grams x 9

Next, she calculates the number of calories that result from the carbohydrates using the following formula:

Calories from Carbs = Carbs grams x 4

Create an application that will make these calculations

-DO NOT use global variables
-Create two variables in main that will hold the two results
-Pass fat and carbs by value, and the result variables by reference
-Output in main

The key with what you need to pass is this: Pass fat and carbs by value, and the result variables by reference. This is what I have to far but I don't understand how to "pass by value, and results by variable" ....

#include <iostream>
using namespace std;
void grams (int);
void calories ();
int main () {
//Get fat and carb grams

[Code] ....

View 2 Replies View Related

C++ :: Pointer - Pass Reference Variable Into Function

Oct 4, 2013

I don't understand how my code not run.

#include "stdafx.h"
#include<iostream>
using namespace std;
struct student{
char name[30];
char birthday[20];
char homeness[50];
float math;

[Code] ....

View 3 Replies View Related

C++ :: How To Pass Address Without Creating Local Variable

May 14, 2012

I am doing a piece of gui code on some embedded system.

I'm trying to find a way of eliminating the local variable kEvent:

Code:
EVENT kEvent;
....

Code:
kEvent = EVENT_UPSTREAM;
xStatus = xQueueSendToBack(getEventProcessorQueue(),&kEvent, 0 );
....

I tried this, it doesn't work:

Code:
xStatus = xQueueSendToBack(getEventProcessorQueue(),(EVENT *)EVENT_UPSTREAM, 0 );

Shouldn't this work?

View 1 Replies View Related

C++ :: Pass Content Of A Variable (int) As Argument To Macro Call

Apr 12, 2013

I am trying to generate a couple of vectors, but the exact number of vectors that will be needed can only be determined at runtime. Therefore I had the idea to use a macro call and text substitution in order to declare the necessary number of vectors. Unfortunately, the arguments of a macro call are always (as far as I know) considered text only. So, the loop in my example below in which I am trying to generate the following code:

vector<int> vector0;
vector<int> vector1;
vector<int> vector2;
vector<int> vector3;

does not work.

#include <iostream>
#include <vector>
using namespace std;
#define declareVec(vecno) vector<int> vector##vecno;

[Code]......

I get an an error message 'vector0' was not declared in this scope.

I also tried to initialize a string or char with the content "0" and then pass this string or char to the macro call, but this did not work either.

Is there any way in which I could use the content of an integer variable or any other variable as arguments for a macro call?

View 1 Replies View Related

Visual C++ :: Put A Message String Through Algorithm / Cryptography?

May 31, 2013

I'm looking for a resource (possibly CPP) for which I could do the following on a windows and linux machine:

1) type a string message into a GUI control (or some other input that can be accessed by the resource).

2) run a resource script that puts the message through a hash function (or a custom hash function) and outputs the hash string.

3) have a reverse function available in order to decrypt the message in an input fashion just like step #1.

what open-source resource might be the best for this? Right now I am imagining typing a message into a text file, saving the file to a hard drive location, running a script on it replacing the old file with a new file that just has a hash string in it, then using that hash string for the encoded message.

View 4 Replies View Related

C++ :: Write A Loop Assigning Variable X To All Positions Of String Variable

Sep 8, 2013

I have to write a loop assigning a variable x to all positions of a string variable and I'm stuck. I don't have extensive experience with arrays and I'm also a bit confused about C-String. The problem is below.

"Given the following declaration and initialization of the string variable, write a loop to assign 'X' to all positions of this string variable, keeping the length the same.

char our_string[15] = "Hi there!";

(Please note this is a 'C-string', not C++ standard string.)"

View 5 Replies View Related

C++ :: How To Pass A String To A Function

Sep 12, 2013

How can I pass the name from the user input to the constructor ?

Code:
#include <iostream>
#include <string>
using namespace std;
class myClass {

[Code]....

View 6 Replies View Related

C/C++ :: How To Pass String From VB6 Into Arduino

Mar 6, 2015

how to pass a string from vb6 into the gsm module ... i am posting vb6 code ... below code passes

check1.caption=11BNELE0455 to MSCOMM2.output...

Static col As Integer

col = 3
lbl: If excelws.Cells(10, col).Value = "" Then
excelws.Cells(9, col).Value = Format(Now, "dd/mm/yyyy")
If (check1.Value = 1) And (Timer1.Enabled = True) Then
excelws.Cells(10, 1).Value = check1.Caption

[Code]...

now i want to access this string a=0455 from c-code of arduino..how can i access this.. below is c-code for arduino uno.what is wrong with it.it is giving me error:invalid conversion from 'int' to 'const char*'.

//decalaration part of my code

#include <SoftwareSerial.h>
char inchar[80][5]; // Will hold the incoming character from the GSMshield
SoftwareSerial SIM900(7, 8);
String textForSMS;

[Code]...

View 1 Replies View Related

C/C++ :: Pass A String As A Parameter And Use It To Open A File?

Feb 21, 2014

why I'm getting an error with this code? I'm trying to pass a string as a parameter and use it to open a file:

class txt{
private:
string tempstring;
vector<string> strings;
char filename[10]; //not using this right now

[code]....

but I get this error:

[Note] no known conversion for argument 1 from 'const string {aka const std::basic_string<char>}' to 'const char*'

I thought strings were just const character arrays

View 3 Replies View Related

C :: Why Cannot Pass The Address Of String During Printf Or Scanf Functions

Jan 24, 2013

Why do we not pass the address of the string during printf or scanf functions like we do for Integer or float variable types?

View 2 Replies View Related

C++ ::  pass Parameters From Other Application To Replace String Within Text File Before Execute Registry Merge

Jan 27, 2014

I'm creating simple console application using Code::Blocks to allow me to pass parameters from other application to replace string within text/registry file before execute the registry merge. Passing parameters to console already success. Now I only have problem with reading file. Example of first line in the registry file is as below.

Windows Registry Editor Version 5.00

However when read into string and output to console using 'cout', it will be show as below with spaces in between.

W i n d o w s R e g i s t r y E d i t o r V e r s i o n 5 . 0 0

Below is my code.

ifstream f("install.reg");
string s((istreambuf_iterator<char>(f)), istreambuf_iterator<char>());
cout << s;

View 6 Replies View Related

C++ :: What Is The Difference Between Pass By Reference And Pass By Pointers

Jan 23, 2013

I've been given an assignment with the below questions.

1. What is the difference between pass by reference & pass by pointers?

2. What is the use of the initialization list in the constructor?

3. What is meant by a reference & its advantage?

4. Class has a reference, pointer and a const. Is it possible to write the copy constructor & assignment operator overloading funciton? how? ( Since reference is there, I'm not sure on how to write for it)

5. Example for a variable decleration and definition? (I know for function but for variable don kw how)

6. static and const static what is the difference??

View 1 Replies View Related

C/C++ :: Change Enum Type Variable To String Type Variable?

Aug 10, 2014

How to change an enum type variable to a string type variable?

View 2 Replies View Related

C++ :: Difference Between Pass By Value And Pass By Reference?

Jul 2, 2014

// explain difference between pass by value and pass by reference

void addOne(int i)
{
i++;
}
void addOne(int& i)
{
i++;
}

View 2 Replies View Related

C++ :: Get Value From String Containing Variable Name?

Nov 2, 2014

As written in the title, I want to be able to extract a variable value from a string containing the variable's name. I know one can use associative containers such as maps but is there another more direct way?

E.g.:

int variable = 5;
string str = "variable";

// how do I get the value of 5 out of the string containing the variable name?

If I am correct, this is called 'Reflection', correct me if I'm wrong.

I know C++ has no inbuilt 'Reflection' class or anything like that so I was wondering if there is a workaround for this kind of thing or is there a library out there which can do this? (that's if I have the name right).

I have found a library called Boost Reflection which sounds like it could do this but I just wanted to make sure that reflection is actually what I am talking about and whether C++ can do what I'm trying to do? I'm not sure how.

View 5 Replies View Related

C :: How To Store First String Into A Variable

Feb 11, 2013

Im trying to write a program that reads in strings and decides if the 1st one is repeated. I cant figure out how to store the first string into a variable, and compare that variable to the rest of the inputted strings.

Code:

#include <strings.h>
#include <stdio.h>
int main () {
//Declared variables
int i;
}

[code]....

View 3 Replies View Related

C++ :: Manipulate A String Into Name Of A Variable?

Feb 1, 2013

The while loop is increased by i++ each time. In the commented line I want to express.When:

i = 1 , player1.cards[j] = random;
i = 2 , player2.cards[j] = random;
void cardScramble()
{
int random;
int i = 1;
while (i <= 4)

[code]....

I tried to define it or manipulate it as a string but didn't work.

View 2 Replies View Related

C++ :: Creating A Class Variable With A String?

May 12, 2013

I have defined a class in a header file; just the class, no templates involved. I have a program where I'm reading in data in string format. Each string consists of a word, a delimiter, and a variable name. Example:

cajun/mustard

I want to take that string and make it the variable name of that class type. It would be implemented along the lines of:

Code:
string str;
//read/process string here, get:
str = "mustard";
createName(str);
//pass string to creator function When the function is called, I should get the variable:
Class mustard;

Thing is, I'm not supposed to know beforehand what the variable names are, only that I create them as they are read in. It could be mustard, it could be Maynard_James_Keenan, it could even be bazinga.

My problem is, what do I do for createName()? I've looked into the concepts of pairing, Factory implementation, and maps, but I don't think they answer my question.

(P.S. if I run into the same variable name being read in twice, what steps can I take to make sure that a duplicate variable isn't created? Do I need to add in code, or does the compiler know to watch for multiple variables of the same name?)

View 6 Replies View Related

C++ :: Variable That Can Hold String And Int In Same Time?

Feb 12, 2014

Is there a variable that can hold string and int in the same time?

If not, what can I do if I want to input data with string and int like a password for an example.

View 3 Replies View Related

C++ :: Converting String Variable To Float

Apr 11, 2014

I would like to convert a string variable to float.When acquiring data from text file, I use:

while( getline( ifs, temp )) {
numberOfFeatures++;
vecteur.clear();
string::size_type stTemp = temp.find(separateur);
number_descriptorEntries=0;

[code].....

the matrix that I obtain is of type vector<Vec> where Vec is a vector of strings.I want to convert each element of matrixe to a float.

View 3 Replies View Related

C++ :: How To Pull Out A Value In String And Store In Variable

Oct 7, 2014

Like if the user enters "38 F" how do I take out the 38 only and store it in a variable? So far my program goes like this:

string text;
double temperature;

cout << "Enter temperature: ";
getline(cin, text); // user enters 38 F
temperature = text // store 38 from string into double

View 1 Replies View Related

C++ :: Age Is Int Variable And Name Is A String - User Input

Jun 18, 2013

I have a problem that states: age is an int variable and name is a string.

What are the values of age and name after the following input statements execute.

cin << age;
getline(cin, name);

if the input is:

a. 23 Lance Grant

b. 23 Lance Grant

Ok I have been fooling around with this book all day. My instructer wants us to build the program instead of just saying

a = 23 Lance Grant

How to input B. I mean when I write the program I do not know how to ask for two lines for one input.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved