C++ :: Reference To A String In Function Parameters

Feb 22, 2015

So I was reading my book and it listed this piece of code. The first piece of code is in the book and the 2nd is just my test on the piece of code. I am curious as to why in the functions parameters there is a reference to aString. I've noticed that removing it has no affect on the outcome of the code.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
bool isPalindrome (string & aString) {

[Code] ....

View 2 Replies


ADVERTISEMENT

C/C++ :: Combining 2 String Parameters And 1 Int Parameter

Mar 20, 2012

#include <stdio.h>
#include <ctype.h>
#include <string.h>  
void interpose(char s[], char a[], int pos) {
    char b[80];

[Code] ....

The program should take 2 string parameter and 1 int parameter for combining. (without any str functions, the functions should be written by coder)

My problem is when i enter int value program crashes.

For example,
str1='Good';
str2=' Morning';
int x= 5;

The output will be 'Good Morning'

View 2 Replies View Related

C++ :: Check Parameters Of Binary String Before Converting To Dec Values

Feb 9, 2015

I'm fairly new to C++ and programming in general and I'm trying to get a program to check the parameters of a binary string before converting that string to dec values. I have the user input 'num' line 39 - 42, but I want to reuse that same value in the 'void bin_to_dec()' function. Is there anyway I can use the same variable between void functions?

13 #include <bitset>
14 #include <sstream>
15 using namespace std;
16
17 void dec_to_bin(){
18 string mess;

[Code] ....

View 3 Replies View Related

C/C++ :: Using X And Y Variables In Function Parameters?

Jan 24, 2015

In my program I created three separate return functions. Each function is labeled:

int boxes(int x, int y);
int leftOver(int x, int y);
double avgItemsShipped(int x, int y, int z);

Is it bad programming practice to use 'x' and 'y' in all of my functions? Should I use the this keyword inside the function? We use this often in my Java class and I know it exists in C++, but I haven't actually seen it used (or used it myself yet).

View 3 Replies View Related

C :: What Does Collection Of Parameters As Argument Of A Function Mean

Aug 27, 2013

What does collection of parameters as argument of a function in C mean? Also any place I can refer to find those parameters?

Googling gives me Parameters and Arguments But not really sure whether that is what is needed.

View 6 Replies View Related

C++ :: Number Of Array Parameters In Function?

Mar 19, 2014

So in this function it is already passing the array into the function but the thing is one parameter being passed into the function and if so how do I go about passing 3 arrays as parameters into the function? Also the program only asks for a user entry of hours for three different cars so why would there be a point in making two additional arrays to be passed into the function?

#include <iostream>
#include <iomanip>
using namespace std;
//passing array into function
double calculateCharges(double hours[], int HoursArrayLocation);//call function

[Code] ....

View 12 Replies View Related

C++ :: Advanced Default Parameters Function

Jul 7, 2014

I'm asking how to create a function with default parameters with the possibility to init the parameters that you need.

Code Example :

#include <iostream>
int func(int a = 1, int b = 2, int c = 3, int d = 4) {
return a + b * c / d;

[Code] .....

View 3 Replies View Related

C++ :: Automatic Conversion For Function Parameters?

Nov 19, 2013

So I'm writing a data structure from scratch as part of a university assignment in c++, and I have to write an iterator for it. The problem involves comparison between constant iterators and normal iterators, and I'm going about it in this way: I wrote a constructor of normal iterator which takes a const iterator as its only parameter, hoping that the comparison operator between two normal iterators will be enough:

btree_iterator(const_btree_iterator<T>&conv):_target(conv._target),_index(conv._index),_last(conv._last){}

(and somewhere else)

template <typename T>
bool operator!=(btree_iterator<T> one,btree_iterator<T> other){
return !(other == one);
}

and I'm testing it in this way:

btree<int> bl(5);//the data structure
auto iter = bl.begin();
iter != bl.cend(); //trying to compare iterator with const iterator

but apparently this is wrong, since the compiler tells me something along the line of "no function 'operator!=' which takes ......" It seems the constructor is alright, since the following works:

btree<int>::iterator i(bl.cend());

Am I getting something fundamentally wrong about it? How is this functionality actually implemented in C++ library containers like vector?

View 9 Replies View Related

C++ :: Error With Function With Objects As Parameters

Apr 9, 2013

I am creating code for a group project in my class. All my group members made a header file with an object in it with their functions. One of the functions in my partner's code uses a data member of mine in the function, so she has the function parameter a object of my object. (This isn't the code but for example)

class B {
friend class A;
void displayAthing(A object) {
cout<<object.thing<<endl;
}

I have this when I call the function in the cpp file

int main() {
A object;
B b;
b.displayAthing(object);
return 0;
}

However, when I compile, it gives me an error that the function does not take 1 arguments.

View 4 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++ :: Variadic Function - Parameters Get Passed In Reverse

Nov 17, 2014

I noticed that when using variadic functions, if I pass the va_arg() as parameter to a function, the parameters get passed in reverse. Is that expected?

For example, the following code outputs
Code:
1 2
2 1

Code:
#include <iostream>
#include <stdarg.h>

void foo_func(int v1, int v2)
{
std::cout << v1 << " " << v2 << std::endl;

[Code] .....

View 3 Replies View Related

C++ :: Setting Up Counters - Using Function / Passing Parameters

Jun 30, 2012

Need setting up counters for this program which should

Given a file of text, assume that
a "word" is 1 or more consecutive, non-whitespace characters
a "sentence" is a series of words terminated by either a period, exclamation point, or question mark

Design a C++ program (using functions/passing parameters) that will

-interactively prompt for and read the name of an input file
-interactively prompt for and read a string to search for
-open the input file (using an input filestream variable) and with one pass through the file
-count the number of "words" in the file
-for each word, make sure all letters, except the first, are lower case - leave the first character unchanged
-count the number of "sentences" in the file
-count the number of letters in the file (A-Z,a-z)
-count the number of consonants in the file (consonants are letters that are not vowels - the vowels are: a, e, i, o, u, A, E, I, O, and U)
-count the number of nonwhitespace characters in the file that are NOT letters
-count the number of times the search string is found in the file (must be an exact match) - search for matches AFTER upper case letters have been coverted to lower case

View 2 Replies View Related

C :: Return 2 Values From A Called Function - Arguments And Parameters

Feb 2, 2013

Is there anyway we can return 2 values from a called function. Example

Code:
float xxxx(float a, float b, float c, float d)
{///
///
///
}

void xxx() {
int e,f,g,h;
////
////
xxx(e,f,g,h);
}

So if I want for example a+b and c+d, can i return those 2 answer? I don't think its possible since I am new into C programming.

View 5 Replies View Related

C++ ::  Function Return Type Template Parameters Can't Be Deduced

Dec 9, 2013

I have this code:

#include <iostream>
#include <vector>
#include <map>
#include <string>
using namespace std;

[Code]...

and it does not compile.

The error is:

test.cpp: In function ‘int main()’:
test.cpp:20:30: error: no matching function for call to ‘func1(std::vector<int>&)’
test.cpp:20:30: note: candidate is:
test.cpp:8:45: note: template<class T, class U> std::map<T, T> func1(U)
test.cpp:8:45: note: template argument deduction/substitution failed:
test.cpp:20:30: note: couldn't deduce template parameter ‘T’

View 3 Replies View Related

Visual C++ :: Passing As Parameters To A Function Characters Coded In UTF 8

Apr 9, 2014

I'm using the Visual C++ Express 2008 and i need to pass as parameters to a function characters coded in UTF 8. My environment is Windows 7. The editor of the VC++ write in UTF 8 or UTF 16? If it writes in UTF 16 how can i change it?

View 2 Replies View Related

C++ :: Variadic Template Function Parameters And Method Pointers?

Oct 24, 2013

I have been experimenting with variadic templates with the aim of caching a call to a class method by storing away the object pointer, method pointer and parameters. I've actually had some reasonable success but have now hit a stumbling block. I now wish to wrap my parameters in a simple template class when I cache them. My success is as follows:

Using variadic template functions to store these pointers and paremeters;

I'm able to pass a method pointer and unwrapped parametersI'm able to pass wrapped parameters on their own.I'm NOT able to pass a method pointer and wrapped parameters I set up a little prototype project to demonstrate the issue and added comments above the function calls to indicate the compilation results. Here is the code:

Code:
#include "stdafx.h"
//////////////////////////////////////////////////
// Basic class with a simple method
//////////////////////////////////////////////////
class MyClass {
public:
char Method( int i, float f ) {
return 'A';

[code]....

But I'm convinced it should take three arguments, the method pointer and two wrapped parameters. Visual studio even suggested it should as shown below:

View 3 Replies View Related

C :: Correct Way To Call A Function Within Main That Has File Pointer Parameters?

Mar 16, 2013

What would be the correct way to call a function within main that has file pointer parameters?

function prototype: Code: void CalculateBoth(int num1, int num2, int*sumPtr, int *diffPtr);

View 2 Replies View Related

C++ :: Passing String Using Reference Operator

Aug 28, 2014

Why it is necessary to use the reference operator here ?

const string& content() const {return data;}

Example in [URL] ....

// classes and default constructors
#include <iostream>
#include <string>
using namespace std;

class Example3 {
string data;

[Code] .....

View 2 Replies View Related

C# :: Null Reference With Connection String

Nov 29, 2014

private DataSet1 GetData(string query) {
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;

The above is erring out with NullReferenceException

View 6 Replies View Related

C# :: Get The Actual String Passed By Reference?

Apr 8, 2015

I have a list of Strings that are passed to a method consecutively by reference from a class. I want to get the string value passed to the method at a point in time. The reason is to perform an if statement.

//this is the class that holds that holds the constants.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace xxx.Functional.xyz.Login {
public class Constants {
public static String Username = "paul";
public static String Code = "4";

[code].....

View 2 Replies View Related

C++ :: Converting Reference Address To Character String

Jun 15, 2014

I'm wanting to convert the reference address held by a pointer into a character string, combine the hexes into a single unsigned long int(using bitwise operators )so I can use the 32bits in conjunction with a separate algorithm to develop a more efficient, but less 'random', number, or should I say bit, generator that I'll be using in a Neural Network, with Genetic Algorithms used to modify the weights.

View 5 Replies View Related

C++ :: Explicit Conversion From String To Class Reference?

May 10, 2013

following code that I'm reading out of the book "The C++ Standard Library".

class C
{
public:
explicit C(const std::string & s); // explicit(!) type conversion from strings.
...

[Code].....

Now I understand that they are saying that an explicit conversion isn't allowed but what I don't understand is what explicit conversion would be happening if there was one allowed.

Specifically I don't understand the const C & elem syntax. How does this work since the collection holds strings. What would be the syntax for how this:

const C & elem

gets strings. I was thinking it was a class reference that someone how converts to a constructor function pointer or something but i'm really confused.

View 4 Replies View Related

C++ :: Undefined Reference To A Function

Jan 19, 2013

The error is this:

#include <iostream>
using namespace std;
void add(int s);
void subtract(int d);
void multiply(int p);
void divide(int q);

[Code] .....

View 2 Replies View Related

C++ :: Undefined Reference To A Function?

Nov 23, 2013

I'm making a program that's essentially a Text-Based Fire Emblem game; it runs calculations and rolls dice and has all sorts of Goodies. However, I have hit a block to the tune of

#ifndef ITEM_H
#define ITEM_H
class Item
{

[Code]....

Up Until I called up a Sword object, it worked fine. But when I compiled it, I got an Undefined Reference to Item::Item() error in Line 8 of Weapon.cpp.

View 2 Replies View Related

C++ :: Returning By Reference From Function

Feb 15, 2015

#include<iostream>
using namespace std;
int &fun() {
int x = 10;
return x;
}
int main() {
fun() = 30;
cout << fun();
return 0;
}

The code outputs 10.

Shouldn't it show an error because x is created locally on stack and gets destroyed on function return?

View 1 Replies View Related

C++ :: Undefined Reference To (function Name)

Oct 2, 2014

Everything seems to be in order and I know my code still has mistakes. I'm just trying to get it to compile and it won't allow it. I've narrowed it down to when I call the functions in main but beyond that I have no clue.

#include <iostream>
#include <cstring>
using namespace std;
void getSize(int num);
void getSpace(int num, int ptr);
void inputData();
void printData();
void destroy();
const int BIG_NUMBER = 100;

[code]....

View 4 Replies View Related







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