1,247 Posted Topics

Member Avatar for ralph1992

> I want to give the customer a 'CurrentAccount' which is inherited from Account; and then store it in an array of Accounts. > How do I go about doing this? You can't. `Account acnts[10];` holds objects of type Account ***by value***. When you try to store an object of …

Member Avatar for phorce
0
8K
Member Avatar for acerious

In general, 1. try to represent an elusive concept as a class - objects are more flexible than code. 2. C++ is one of the few programming languages with a strong sense of initialization and deinitialization - exploit it. For example: #include <iostream> int recurse( int n ) { static …

Member Avatar for vijayan121
0
142
Member Avatar for nuclear

Read 20 chars into a `std::strin`g: #include <fstream> #include <string> int main() { std::ifstream file( "file.txt" ) ; std::string str ; enum { NCHARS = 20 } ; // read upto NCHARS chars into str str.reserve(NCHARS) ; // not essential file >> std::noskipws ; // do not skip white space …

Member Avatar for vijayan121
0
187
Member Avatar for Vegito1991

> why the remove and rename function cannot perform? > everytime remove the original (hello.txt), it still remain. Probaly because you have not closed the files before attempting these operations. #include <cstdio> #include <fstream> #include <string> #include <iostream> std::string replace( std::string line, const std::string& substr, const std::string& replace_with ) { …

Member Avatar for Vegito1991
0
28K
Member Avatar for FearlessHornet

You need to link both the DLL and the exe to the same instance of the run-time library. Ie. link both with the shared version of the standard library: either **/MDd** (Debug) or **/MD** (Release)

Member Avatar for FearlessHornet
0
569
Member Avatar for Echo89
Member Avatar for danibecse

> How to print a sentence (including white spaces) from a file ? > Or How to print entire text file which has a paragraph? Assunming that you have a compiler that is not antique: #include <iostream> #include <fstream> #include <string> int main() { std::string filename ; std::cout << "file …

Member Avatar for Daniel BE
0
3K
Member Avatar for BevoX

A fast (very fast) implementation of the Sieve of Atkin: [url]http://cr.yp.to/primegen.html[/url] The less well known Sieve of Sundaram: [CODE=C++1x]#include <vector> #include <algorithm> #include <iostream> // sieve of sundaram (naive implementation) std::vector<int> generate_primes( int N ) { const int M = N / 2 ; std::vector<bool> sieve( M, true ) ; …

Member Avatar for Microno
1
678
Member Avatar for nyfan68

Ideally use a `std::vector<>` to hold the names and numbers. If you **must** use arrays (you have a teacher ... ), you need to keep track of the size manually. Something like: struct PhoneBook { // ... void add( const Name& n, const PhoneNumber& p ) { if( current_size < …

Member Avatar for vijayan121
0
201
Member Avatar for yxBen

`std::array<>` is an **aggregate** which wraps a C-style array. It has no user-defined constructors. `{1,2,3,4,5}`is therefore not interpreted as a brace-enclosed `initializer_list<>` The situation is analogous to: struct X { int a[2] ; } ; X one = { 1, 2 } ; // ***error: missing braces around initializer for …

Member Avatar for yxBen
0
674
Member Avatar for andrew mendonca

//double getMean( double scores[], int numScores ) double getMean( const double scores[], int numScores ) // **** const { /* // You may want to ignore this bit for now. using limits = std::numeric_limits<double> ; if( numScores < 1 ) return limits::has_quiet_NaN ? limits::quiet_NaN() : limits::signaling_NaN() ; */ // int …

Member Avatar for vijayan121
0
207
Member Avatar for Vish0203

Something like this: // C++11 std::string generate_file_name( const std::string& name, const std::string& college ) { static int slno = 0 ; return name + '_' + college + '_' + std::to_string( ++slno ) ; } // or C++98 std::string generate_file_name( const std::string& name, const std::string& college ) { static int …

Member Avatar for Vish0203
0
132
Member Avatar for GamerDJX

Write it in two stages, perhaps. You already have the code for converting a decimal number to some specified base. Write the code to convert in the reverse direction - from some specified base to decimal. Now conversion from base **A** to base **B** can be done in stages: * …

Member Avatar for vijayan121
0
223
Member Avatar for superjacent

> How is that the "My Name.." bit, which I believe to be a const char* or string literal > be somehow resolved to a String object for the purposes of the function. the String class has a (non-explicit) single argument constructor which takes a [ICODE]const char *[/ICODE]. this also …

Member Avatar for Museful
0
256
Member Avatar for angham kh

Split the line using a `std::istringstream` ? #include <vector> #include <string> #include <sstream> std::vector< std::string > split_into_ws_separated_columns( const std::string& line_from_file ) { std::vector< std::string > columns ; std::istringstream stm(line_from_file) ; std::string col ; while( stm >> col ) columns.push_back(col) ; return columns ; }

Member Avatar for angham kh
0
1K
Member Avatar for AutoPython

See: http://www.daniweb.com/software-development/cpp/threads/438942/flter-a-log-file-using-c#post1886475

Member Avatar for rubberman
0
433
Member Avatar for coroshea

Something like this: #include <iostream> #include <vector> template < typename T > struct my_class : public std::vector<int> { typedef std::vector<T> base ; using base::iterator ; // etc explicit my_class( const char* n ) : name(n) {} // ... private: std::string name ; friend inline std::ostream& operator<< ( std::ostream& stm, const …

Member Avatar for vijayan121
0
140
Member Avatar for sofy

> my task is to type 20 integer numbers from 0 to 99 as the input data. > But i have problem for my next task, which is to display prime numbers from the input data. 2, 3, 5 and 7 are prime numbers. If an integer between 8 and …

Member Avatar for sofy
0
363
Member Avatar for Carc369

> Now I just have to alter it so it doesn't read in repeat words in the book. The simplest way would be to use a `std::set<>` or `std::unordered_set<>` to filter out the non-uniqe words. #include <iostream> #include <fstream> #include <string> #include <set> #include <vector> #include <iterator> // http://en.cppreference.com/w/cpp/container/vector std::vector< …

Member Avatar for vijayan121
0
700
Member Avatar for Carc369

void encode() { char userInput[512], direction[32], keyword[32]; int transposition; cout << "Enter the text to be encoded: "; cin.get( userInput, sizeof(userInput) ) ; // unformatted input cout << "Enter direction (Forwards or Reverse): "; cin.get( direction, sizeof(direction) ) ; // unformatted input cout << "Enter transposition value (0...25): "; cin …

Member Avatar for vijayan121
0
568
Member Avatar for Instinctlol

Let us say we have a function: // return a string with all occurrences of substr in str replaced with replacement std::string replace_all( const std::string& str, const std::string& substr, const std::string& replacement ) ; This function can be called with many different input sets (each set being a tuple of …

Member Avatar for vijayan121
0
2K
Member Avatar for phorce

> The singleton design pattern is unique in that it's a strange combination: its description is simple, yet its implementation issues are complicated. - Andrei Alexandrescu in 'Modern C++ Design' If Animal is a singleton - that is a second object of type Animal cannot exist - its singletonness can …

Member Avatar for L7Sqr
0
228
Member Avatar for Seni0RRunn3r

> I can't figure out how to use the cin.peek for the extracting numbers or charachters from the randomly typed input `std::istream::peek()` will retrieve, but will not extract the character from the input buffer (the charaxter remains in the input buffer). http://en.cppreference.com/w/cpp/io/basic_istream/peek Use `std::istream::get()` to read and extract the next …

Member Avatar for Seni0RRunn3r
0
2K
Member Avatar for Elixir42

C++11: `std::to_string()` http://en.cppreference.com/w/cpp/string/basic_string/to_string

Member Avatar for Elixir42
0
3K
Member Avatar for prahesh

Use `std::map<>` with `std::pair< e_ServerName1, e_ServerName2 >` as the key_type and `e_UserName` as the mapped_type. http://en.cppreference.com/w/cpp/container/map #include <map> enum e_UserName { one, two, three, four /* etc. */ } ; enum e_ServerName1 { Venus, Mars, Earth } ; enum e_ServerName2 { Jupiter, Pluto, Neptune, Saturn } ; int main() { …

Member Avatar for prahesh
0
190
Member Avatar for daino

The Nuwen build of MinGW includes a number of pre-built libraries; **libjpeg-8d** is one of them. http://nuwen.net/mingw.html Nuwen MinGW is distributed as a single self-extracting archive and can be installed from the command line.

Member Avatar for vijayan121
0
3K
Member Avatar for SuburbanSamurai

To read a whole line (including whitespace) into a string, use `std::getline()` http://www.cplusplus.com/reference/string/getline/ To read the contents of a file, where each data set consists of the name of a state followed by three numbers, the code would be something like: std::ifstream file ("list.txt") ; std::string name_of_state ; int number …

Member Avatar for Gonbe
0
223
Member Avatar for Vaspar

> I am facing problem using float > in loop its value stuck at 8388608.00 First read up a bit on the representation of floating point numbers and loss of precision. http://www.cprogramming.com/tutorial/floating_point/understanding_floating_point_representation.html Then, try out this program: #include <limits> #include <iostream> #include <iomanip> int main() { typedef std::numeric_limits<float> limits ; …

Member Avatar for Vaspar
0
165
Member Avatar for 0773247886

+1 Gonbe and deceptikon. People do learn by going through, reasoning about, and then understanding a solution to a problem. Someone learning programming is not all that much different from a child learning to speak - the child learns by listening to people speak correctly.

Member Avatar for vijayan121
0
173
Member Avatar for Vaspar

Something like this: enum { N = 1024*1024*1024 } ; // 1G times double value = 1.0 / 3.0 ; double plus_result = 0 ; for( int i=0 ; i < N ; ++i ) plus_result += value ; const double multiplies_result = value * N ; std::cout << std::fixed …

Member Avatar for TrustyTony
0
258
Member Avatar for ShEeRMiLiTaNt

> but now the problem I am having that it only deletes repeated pairs not all repeats. How can I make it so that it deletes all the repeats in the word? If you are allowed to have a different order of chars in the result, just sort the original …

Member Avatar for vijayan121
0
2K
Member Avatar for gtsreddy

As of now, in terms of strict conformance, clang with its libc++ is ahead of the rest of the pack. http://clang.llvm.org/ It is also the best compiler for people starting out to learn C++; clang's clear and expressive diagnostic messages are much easier for beginners to understand. (GCC 4.8 has …

Member Avatar for vijayan121
0
718
Member Avatar for DelilahDemented

> The last line is matching, but because it thinks the array size is zero it drops out and states that it doesn't match. Haven't looked at any of the logic except this: while(inFile) // the file stream is not yet at eof after the last line has been read …

Member Avatar for DelilahDemented
0
192
Member Avatar for pendo826

> i need to restrict the user from inputting an integer and string when inputting a char. Read the input into a string. Verify that the string consists of precisely one non-digit character. char get_single_nondigit_char() { std::string input ; while( std::cout << "enter a single non-digit, non-whitespace char: " && …

Member Avatar for Lucaci Andrew
0
198
Member Avatar for TexasJr
Member Avatar for vijayan121
0
188
Member Avatar for Jsplinter

> As far as I can tell, the main reason to declare a data member as const is to remind the user of that class not to change it's value. A const member variable is an object that is initialized during construction of the object and is never changed after …

Member Avatar for mike_2000_17
0
280
Member Avatar for phfilly

Use a `std::istringstream` to extract the tokens from the string. http://www.artima.com/cppsource/streamstrings3.html #include <iostream> #include <string> #include <sstream> #include <cmath> inline void error() { std::cerr << "error in input\n" ; } int main() { std::string input ; while( std::cout << "? " && std::getline( std::cin, input ) ) { std::istringstream stm(input) …

Member Avatar for WaltP
0
392
Member Avatar for Kamina00

> How long has C++ supported this? C++ has never supported this. It wasn't supported in 1998 and it still isn't supported today. Variable length array is a C99 feature. In C++, use `std::vector<>` if similar functionality is required. http://www.codeguru.com/cpp/cpp/cpp_mfc/stl/article.php/c4027/C-Tutorial-A-Beginners-Guide-to-stdvector-Part-1.htm > I am using Dev-CPP 4.9.9.2 with GCC version 3.4.2-20040916-1. …

Member Avatar for Kamina00
0
220
Member Avatar for hillman.chen

> Also, I would get the input from the user, and than form a string composed by the name and pet strings. Yes. Then randomly shuffle the string and pick the first six chars. Likwwise, for the string containing digits (pick the first two after a shuffle). Randomly shuffle the …

Member Avatar for vijayan121
0
419
Member Avatar for nquadr

In general, prefer to declare a variable closest to its point of use. Local variables should have no more visibility than absolutely required; define them when you need them, and let them go out of scope when you're done with them. For instance, for( unsigned int i = 0 ; …

Member Avatar for nquadr
0
221
Member Avatar for Carpetfizz

#include <cmath> inline double log_to_base( double value, double base ) { return std::log(value) / std::log(base) ; }

Member Avatar for vijayan121
0
68
Member Avatar for Slate2006

> a template that converts an array of type T to an array of type char, which can then be used as the operand to sizeof to get the number of elements: [code]template <typename T, size_t N> char (&array(T(&)[N]))[N];[/code] another way to use the same template idea (which i find …

Member Avatar for Sebelius
0
1K
Member Avatar for bryangino20

1. the names **x**, **v**, **f** and **i** can be unambiguously resolved by name look-up; except that **f** may be the name of a function with two or more unambiguous overloads. 2. **v** is either a pointer (other than pointer to possibly cv-qualified void) or an object which has an …

Member Avatar for mike_2000_17
0
501
Member Avatar for tmoran1016

In ArrayList.cpp, do not redefine the type `ArrayList` That would be a violation of ODR. http://en.wikipedia.org/wiki/One_Definition_Rule Instead, `#include "ArrayList.h"` > I assume the problem is there is no operator != in the Country.h file. Yes. The problem is that there is no `operator !=` anywhere. > our instructor told us …

Member Avatar for vijayan121
0
186
Member Avatar for jongiambi

Date.h requires an include guard. http://en.wikipedia.org/wiki/Include_guard Either: ////////// date.h //////////// class Date { // ... bool sameMonth( string aMonth, string aMonth2 ) const ; // *** const added }; //////// date.cpp /////////// #include "date.h" bool Date::sameMonth( string aMonth, string aMonth2 ) const // *** note the Date:: { return aMonth …

Member Avatar for vijayan121
0
288
Member Avatar for marius2010

> Dudes I am newbie to C++ and forums. I thought i was helping that dude. Fair enough. Perhaps you should have waited till marius2010 demostrated that a genuine attempt to solve the problem was made. Code snippets are a genuine aid in learning programming - one good snippet is …

Member Avatar for WaltP
0
369
Member Avatar for demingd

> im writing a program that creates a dynamic array then input numbers(not exceeding 100). Why do you need an array with dynamic storage duration? You know the size of the array at compile time - 100 - and that is not a huge number. constexpr std::size_t ARRAY_SIZE = 100 …

Member Avatar for WaltP
0
229
Member Avatar for bladelord76

//////////////////// a.h ////////////////////////// class C ; class A { public: void setInfo(int age, C *ptrToC); }; //////////////////// b.h ////////////////////////////// #include "a.h" class B { private: A exampleofA; }; //////////////////// c.h ///////////////////////////////// #include "b.h" class C { public: void randomFunction(); private: A secondexampleofA; B exampleofB; }; /////////////////////// a.cc ////////////////////////// #include "a.h" …

Member Avatar for bladelord76
0
266
Member Avatar for Tinnin

In string::const_iterator url_beg(string::const_iterator b, string::const_iterator e) { static const string sep = "://"; // ... return e; } the value returned is always **e** (end). Instead, return an iterator to the begin of the url. Something like: string::const_iterator url_beg( std::string::const_iterator b, std::string::const_iterator e ) { static const string sep = …

Member Avatar for Tinnin
0
289
Member Avatar for nyquist

Some other options are, OpenCV: You could just use OpenCv's Mat class with an OpenCV primitive data type; and then just store 0 or 1 as the values. cv::Mat matrix4( 100, 60, CV_8U ) ; Standard C++ library: #include <vector> #include <bitset> // fixed width matrix of bits std::vector< std::bitset<100> …

Member Avatar for vijayan121
0
6K

The End.