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


ADVERTISEMENT

C++ :: Pass 2 Arrays Into Void Function And Return Values To One Function?

Feb 12, 2014

I'm trying to pass 2 arrays into a void funtion, and return values to one function.

this is the the program I'm working with, after I'm done I have to split it into 3 files, a header, a main, and a separate cpp file for the functions to live in.

#include <iostream>
using namespace std;
void processArrary(int numberCount[], int Numbers[], int intnumberSize, int numberCountSize);
int main() {
int Scores[26] = {76, 89, 150, 135, 200, 76, 12, 100, 150, 28, 178, 189, 167, 200, 175, 150, 87, 99, 129, 149, 176, 200, 87, 35, 157, 189};
int numberCount[8] = { 0 };

[code]...

The goal of this program is to separate and count the groups of numbers then output the amount of numbers in each group. Near as I can tell, everthing should work, but I'm getting all zeros to be displayed in each group.

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++ :: Retrieving File Object From Function Then Pass To Another Function?

Jun 27, 2014

I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)

My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.

Code:
#include <iostream> //I/O
using namespace std;
#include <fstream> //files
using namespace ios;
int FileOpen(string fileName) {
ifstream oFile (fileName); //attempt to open file

[Code] ....

View 1 Replies View Related

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 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 :: How To Pass Main Function Argument To Some Other Function

Dec 26, 2014

I am writing a program in which a Fucntion has to be wriiten to parse the Command Line . When I include Code for parsing in main fuction iteslf ,its run ok . But I want to make a fucntion of that code and call it from main ,than it show Segmentation error .

By using Debugging I found Some thing is mess with " -m" Parameter of Command line , But Cant Rectify it ..

Code:
int main (int argc, char *argv[]){
//get_parameter_value(argc,argv);
// buffer[packet_size+1]= char ("'");
while (argc > 1) {
if (argv[h][0] == '-')

[Code] .....

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 Value From One Function To Another

Mar 30, 2014

In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.

ReadNew function reads the file....check to see if it exist

CreateNew function creates a new file.

In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions

Here is my code.

Code:
//Create a file, append to it, and read it.

#include <iostream>
#include <fstream>
#include <string.h>
#include <stdio.h>
using namespace std;
char filename[256];
string n;
string filelist;
void CreateNew(ofstream & FileNew);

[Code]...

View 3 Replies View Related

C++ :: Pass Array From One Function To Another

Mar 15, 2013

I'm trying to pass an array from one function to another without resorting to pointers and I have to use Pass by Reference. I can't seem to figure it out. I've been looking at many examples and just don't get it.

the function createAbc makes an array populated with the Alphabet. I need to pass that into my display function so that i can work with the array there. I don't know how to pass it in there... :(

#include "stdafx.h"
#include <iostream>
#include <cctype>

[Code]...

View 9 Replies View Related

C++ :: Pass From Function To Main

Apr 24, 2014

Why the value does not return; Here is code

#include <iostream>
#include <string>
#include <ctime> // to use the time function
#include <cstdlib>
using namespace std;
int getUserChoose (int);

[Code] ....

here is the output

Welcome to the program of Rock, Paper, Scissors
The computer is ready to play the game
Are you ready to play the game
Y for yes and N for no
Y
R = Rock; P = Paper; S = Scissors
R
You have choose Rock
1TN
1RM
0U
0C

View 5 Replies View Related

C++ :: Pass Two Strings To A Function?

Dec 3, 2014

I am writing a driver program that will eventually need to pass two strings to a function I am writing in a separate file. I am reading data from a file that is formatted like this:

ac: and
amo: love
amor: love

[Code].....

Only a few of the words are actually being processed in the way I want. It appears that only words followed by a comma are processed correctly.

View 1 Replies View Related

C++ :: Pass Object As A Pointer In Function

Apr 12, 2013

i need to pass myboard.board (board is in the class Cboard and it is an array of int) to a function in a class called piece however this is troubling . i need to pass it as pointer os that i could change its value here under is my code.

main.cpp Code: #include<iostream>
#include"board.h"
#include "pieces.h"

[Code].....

View 7 Replies View Related

C++ :: How To Pass Function Return From Switch

Aug 23, 2013

How to do i fix this code im not good at using function, im trying to pass a statement from switch to my double passengersR i always come out with a error

this output:
Name passenger:
Enter number passenger:
Choose from A to D
if choose A
Total Regular Passenger: 6.19624e-312

did i do something wrong im not really good at function and im trying to learn how to pass switch to void function

Code:

#include<conio.h>
#include <iostream>
#include <Iomanip>
#include <string>
using namespace std;
double passengersR ()
{ double m;

[Code]...

View 4 Replies View Related

C :: How To Pass 2 Array Pointers To A Function

Aug 4, 2013

How would I pass let say 2 array pointers to a function X , allocate memory for them in X , fill them with values and get them back in my main function without creating a structure.

example:

Code:

void X(int *a, int*b){
a= malloc ...
b = malloc ...
// fill a and b
return them back to the main function
}
void main(){

[Code]...

View 3 Replies View Related

C++ :: Pass A Pointer Into Function - Value Of Char?

Jan 2, 2014

I'm having a problem understanding something with pointers. I was trying to pass a pointer into a function in MSVC-2013, like

char* charptr;
and then calling
myfunct(charptr);

and then inside the function i would set charptr equal to another char ptr, simply like

charptr = anothercharptr;

But this actually caused a compile failure in MSVC, saying charptr is being used without being initialized. in Code::Blocks it just gives buggy output.

I solved this issue by calling the function like

myfunct(&charptr);

and declaring the function like
myfunct(char**);

and then I had to dereference the charptr in the function when assigning it to another ptr, so
*charptr = anothercharptr;

It seems like you should be able to just pass a ptr into a function and change its address to that of another pointer? My main question is really, what is the value of a pointer? I thought the value of a pointer was just the memory address it contains. But then I had to reference it to pass it into the function.

What is the difference between the value of the char* charptr written as either charptr and &charptr?

View 1 Replies View Related

C++ :: How To Pass Char To Function Void

Jun 1, 2013

How to pass the char something[8][8] for example to function void ( char pass.....)???

View 7 Replies View Related

C++ :: Array Into Function As Parameter Pass

May 2, 2013

I have been working on this all day, and its due in like an hour and a half. I have done everything the program wants except the last part. Here is the assignment:

Write a program that inputs 10 integers from the console into an array, and removes the duplicate array elements and prints the array. You may assume that all the integers are between 0 and 100, Write at least 1 function in addition to the main function, and pass an array into that function as a parameter. e.g.

Please enter your 10 numbers: 1 2 3 4 5 6 7 8 9 10
The array contains: 1 2 3 4 5 6 7 8 9 10

Please enter your 10 numbers: 1 1 3 3 3 6 7 8 9 9
The array contains: 1 3 6 7 8 9

Please enter your 10 numbers: 1 1 1 1 1 1 1 1 1 1
The array contains: 1

The bolded part is what I cant get to work. I have tried this and it keeps telling me I have not identified the items when I have.

Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;

[Code]....

View 1 Replies View Related

C++ :: How To Pass A Void Function As Parameter

Oct 20, 2013

How can I pass a function as a parameter? I have a class that I'm trying to reuse and one of the methods in this class need to take three parameters, two ints and a function. In other words I want to be able to call a custom function every time this method is invoked when used in other classes. The function I want to call will not return any values, its a void function.

In my Class:

void Utility::someFunction(int var1, int var2, void customFunction) {
int num1 = var1;
int num2 = var2;

[Code] .....

View 9 Replies View Related

C++ :: Pass Address Of Pointer To Function

Sep 25, 2014

#include <iostream>
using namespace std;
void myfunc(int* ); // what do i put in these parameters to accept a mem loc of a pointer
int main () {
int x = 5;

[Code] .....

SOLUTION:

#include <iostream>
using namespace std;
//Purpose to create a function that returns a pointer to a pointer
int** myfunc(int**);
int main () {
int x = 5;

[Code] ....

View 3 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/C++ :: How To Pass Multiple Values From One Function To Another

Mar 4, 2015

I need to pass multiple values from one function to another and how to do this. Here is my code so far.

#include <iostream>
#include <string>
#include <cctype>
#include <fstream>
using namespace std;
//Function Prototypes//
int charString(string, string, string);
string reverseString(string, string, string);

[Code]...

I basically need to take line1, line2, and line3 and return them to the reverseString function. Also, I am not allowed to do anything like make my own classes. I have to stick to the basics and no higher level programming techniques since we have not learned them yet.

View 5 Replies View Related

Visual C++ :: Pass A Handle To A Function

May 5, 2013

Visual C++ 2010

I'm using SFML with Visual C++ and need to pass a handle to a function. I've tried to find this on the web with no luck.

The handle happens to be a sprite defined as: sf::Sprite Numbers(MyNumbers);

Now I want to pass "Numbers" to a function.

-
-
getFrame(Numbers);
-
-
???? getFrame(??????) {
Numbers.SetSubRect(sf::IntRect(0,0,63,63));
return ????
}

How do I do this?

View 1 Replies View Related

C++ :: How To Pass N-dimensional Array To Function

Sep 4, 2014

If a function takes N-dimensional array as a parameter, what is generic way to do that? I couldn't figure out a nice way to do that.

View 7 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 :: How To Pass Symbolically Name Of Struc Member To Function

Oct 31, 2013

I have a struct with several members, for instance:

insert
Code:
typedef struct {
float u;
float v;
float w;
} mystruct;
main ()
mystruct test;
...

I have a piece of code that should operate on test.u that looks like this:

switch (j) {
case 0:
f = test.u + ...;
break;
case 1:
f = X - test.u;
break;
case 2:
f = test.u + 2;
break;
}

Now I would like to use a similar piece of code but for the other members, test.v and test.w. In principle I could copy the piece of code above and just replace test.u by test.v or test.w. Since it is the same code for all members, I would like to avoid this (copying many times the same piece of code) and replace it by a call to function. The question is, how to pass the name of the struct member I am considering to the function ? How can I tell the function, operates on member .u or .v ? Would it be possible to have a generic piece of code

insert
Code:
function (member y,...)
switch (j) {
case 0:
f = test.y + ...;
break;
case 1:
f = X - test.y;
break;
case 2:
f = test.y + 2;
break;
}

where the function could be called with function(u) or function(w) and would replace automatically .y by .u or .w ?

View 3 Replies View Related







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