Search Results

Search found 1031 results on 42 pages for 'iostream'.

Page 11/42 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • C++ enumeration

    - by asli
    Hi,my question is about enumeration,my codes are : #include<iostream> using namespace std; int main() { enum bolumler {programcilik,donanim,muhasebe,motor,buro} bolum; bolum = donanim; cout << bolum << endl; bolum += 2; // bolum=motor cout << bolum; return 0; } The output should be 1 3 but according to these codes the error is: error C2676: binary '+=' : 'enum main::bolumler' does not define this operator or a conversion to a type acceptable to the predefined operator Error executing cl.exe. 111.obj - 1 error(s), 0 warning(s) Can you help me ?The other question is what can I do if I want to see the output like that "muhasebe"?

    Read the article

  • C++: can't static_cast from double* to int*

    - by samoz
    When I try to use a static_cast to cast a double* to an int*, I get the following error: invalid static_cast from type ‘double*’ to type ‘int*’ Here is the code: #include <iostream> int main() { double* p = new double(2); int* r; r=static_cast<int*>(p); std::cout << *r << std::endl; } I understand that there would be problems converting between a double and an int, but why is there a problem converting between a double* and an int*?

    Read the article

  • #include <string> adding ~43 KB to my exe

    - by Lienau
    I'm using Code::Blocks to write my program and when I include <string> (or <iostream>) the size of my exe grows. My program is very simple and I need to keep it small <20kb. I'm pretty sure this is happening because of the C++ Standards Committee swapped the old .h versions for many new libraries without the .h. But how would I keep it from adding the ~43kb? Are there settings for Code::Blocks so that it wont add the extra kb or is there another native lib I can use?

    Read the article

  • Why is this c++ string concatenation missing a space?

    - by danutenshu
    I am working with c++ strings, and am a beginner at programming. I am expecting: 99 Red Balloons But I am receiving: 99 RedBalloons Why is that? #include <string> #include <iostream> using namespace std; int main() { string text = "9"; string term( "9 "); string info = "Toys"; string color; char hue[4] = {'R','e','d','\0'}; color = hue; info = "Balloons"; text += (term + color + info); cout << endl << text << endl; return 0; }

    Read the article

  • How do i use 'auto' in C++ (C++0x) ?

    - by LoudNPossiblyRight
    What do i have to do to this code to make it compile, it's braking around this line: auto val = what.getObject(); #include<iostream> using namespace std; class CUP{ public: void whatsHappening(){} }; class MUG{ public: void whatsHappening(){} }; class CupThrower{ public: CUP cp; CUP getObject(){ return cp;} }; class MugThrower{ public: MUG mg; MUG getObject(){return mg;} }; template <typename T> void whatsHappening(T what){ auto val = what.getObject(); //DOES NOT COMPILE val.whatsHappening(); } int main(){ CupThrower ct; MugThrower mt; whatsHappening(ct); whatsHappening(mt); return 0; } i am using VS2008 to compile.

    Read the article

  • C++ include header conventions

    - by user231536
    Suppose I have a file X.h which defines a class X, whose methods are implemented in X.cc. The file X.h includes a file Y.h because it needs Y to define class X. In X.cc, we can refer to Y because X.h has already included Y.h. Should I still include Y.h in X.cc ? I understand that I don't need to and I can depend on header guards to prevent multiple inclusions. But on the one hand, including Y.h makes X.cc a little more independent of X.h (can't be completely independent of course). What is the accepted practice? Another example: including <iostream> in both .h and .cc files. I see some people do this and some don't.

    Read the article

  • C++: Binding to a base class

    - by Helltone
    The following code works, but I'm not sure it is correct/portable. #include <iostream> #include <tr1/functional> class base { public: base(int v) : x(v) {} protected: int x; }; class derived : public base { public: bool test() { return (x == 42); } }; int main(int argc, char* argv[]) { base b(42); if(std::tr1::bind((bool (base::*)()) &derived::test, b)()) { std::cout << "ok\n"; } return 0; }

    Read the article

  • C++: conjunction of binds?

    - by Helltone
    Suppose the following two functions: #include <iostream> #include <cstdlib> // atoi #include <cstring> // strcmp #include <boost/bind.hpp> bool match1(const char* a, const char* b) { return (strcmp(a, b) == 0); } bool match2(int a, const char* b) { return (atoi(b) == a); } Each of these functions takes two arguments, but can be transformed into a callable object that takes only one argument by using (std/boost)bind. Something along the lines of: boost::bind(match1, "a test"); boost::bind(match2, 42); I want to be able to obtain, from two functions like these that take one argument and return bool, a callable object that takes two arguments and returns the && of the bools. The type of the arguments is arbitrary. Something like an operator&& for functions that return bool.

    Read the article

  • How to dump STDIN to a file, using C++ STL?

    - by Jimm Chen
    HHello all, this is a straight forward question, but not a straight forward answer can be found by just Googling today. Hope someone can show me a concise answer before I dig into those thick C++ books and finally find the solution out. Thank you. I'm writing this program so to make a workaround in this issue: Why do I get 'Bad file descriptor' when trying sys.stdin.read() in subversion pre-revprop-change py script? Note: Content from STDIN may be arbitrary binary data. Please use C++ STL functions, iostream, ifstream etc . If the file creation/writing failed, I'd like to catch the exception to know the case.

    Read the article

  • How to read the whole istream correctly?

    - by L.Lawliet
    Here is a simple code to print all characters of a txt file on screen: #include <iostream> #include <fstream> #include <string> using namespace std; int main() { int **i; int j,k; char a; ifstream test("test.txt", ios::binary); while((a=test.get())!=-1)//if I use "while(!test.eof())" here, how to avoid the output of the last character(-1) to std::cout, or any ostream objects? { putchar(a);//also change this to putchar(test.get()); } getchar(); } As I noted in the code, if I use "test.eof()" to judge the end of test.txt, I'll always get an extra blank at the end of the output. How to avoid it?

    Read the article

  • Looking at the C++ new[] cookie. How portable is this code?

    - by carleeto
    I came up with this as a quick solution to a debugging problem - I have the pointer variable and its type, I know it points to an array of objects allocated on the heap, but I don't know how many. So I wrote this function to look at the cookie that stores the number of bytes when memory is allocated on the heap. template< typename T > int num_allocated_items( T *p ) { return *((int*)p-4)/sizeof(T); } //test #include <iostream> int main( int argc, char *argv[] ) { using std::cout; using std::endl; typedef long double testtype; testtype *p = new testtype[ 45 ]; //prints 45 std::cout<<"num allocated = "<<num_allocated_items<testtype>(p)<<std::endl; delete[] p; return 0; } I'd like to know just how portable this code is.

    Read the article

  • Matrix multiplication using Matrix Template library (MTL 4)

    - by Lxc
    The program is as following: #include <iostream> #include <boost/numeric/mtl/mtl.hpp> using namespace mtl; int main(int argc, char* argv[]) { dense_vector<double> a(5,1.0); dense_vector<double> b(5,2.0); a * trans(b); } I want to calculate a * trans(b), but there is a compling error :C2893. Will someone help me? Thanks a lot!

    Read the article

  • Problem with basic program using Boost Threads in c++

    - by Eternal Learner
    I have a simple program which creates and executes as thread using boost threads in c++. #include<boost/thread/thread.hpp> #include<iostream> void hello() { std::cout<<"Hello, i am a thread"<<std::endl; } int main() { boost::thread th1(&hello); th1.join(); } The compiler throws an error against the th1.join() line. It says " Multiple markers at this line - undefined reference to `boost::thread::join()' - undefined reference to `boost::thread::~thread()' "

    Read the article

  • Disallow private constructor invocation in friend function

    - by user2907032
    Is there any way to not allow private construction in friend function, In case we do have private constructor with friend function in our class. Only Static method should be responsible for object creation and other than this compiler should flash error message #include <iostream> #include <memory> using namespace std; class a { public: void see () { cout<<"Motimaa"; } static a& getinstance() { static a instance; return instance; } private: a() {}; friend void access(); }; void access () { a obj; obj.see();//still friend function can access } int main() { a::getinstance().see(); access(); return 1; }

    Read the article

  • Output Unicode to Console Using C++

    - by Jesse Foley
    I'm still learning C++, so bear with me and my sloppy code. The compiler I use is Dev C++. I want to be able to output Unicode characters to the Console using cout. Whenver i try things like: # #include directive here (include iostream) using namespace std; int main() { cout << "Hello World!\n"; cout << "Blah blah blah some gibberish unicode: ÐAßGg\n"; system("PAUSE"); return 0; } It outputs strange characters to the console, like µA¦Gg. Why does it do that, and how can i get to to display ÐAßGg? Or is this not possible with Windows?

    Read the article

  • OpenCv not initializing usb camera

    - by brainbarshan
    I am trying to capture video from usb camera using OpenCv. #include <highgui.h> #include <iostream> using namespace std; using namespace cv ; int main() { VideoCapture cap (-1); if(!cap.isOpened()) cout << "Cam initialize failed" ; else cout << "Cam initialized" ; return 0; } It is failing to initialize the camera. cap.isOpened() is returning zero. The same program, with same version of OpenCv and same usb camera, is correctly running in my friend's machine. I am running fedora 16. I did some searching in Google and Stack Overflow. But no useful help. Any idea ?

    Read the article

  • why this signal handler is called infinitely

    - by lz_prgmr
    I am using Mac OS 10.6.5, g++ 4.2.1. And meet problem with following code: #include <iostream> #include <sys/signal.h> using namespace std; void segfault_handler(int signum) { cout << "segfault caught!!!\n"; } int main() { signal(SIGSEGV, segfault_handler); int* p = 0; *p = 100; return 1; } It seems the segfault_handler is called infinitely and keep on print: segfault caught!!! segfault caught!!! segfault caught!!! ... I am new to Mac development, do you have any idea on what happened?

    Read the article

  • Whats wrong with the following code, its not compiling

    - by Ganesh Kundapur
    #include <iostream> #include <vector> using namespace std; class Base { public: void Display( void ) { cout<<"Base display"<<endl; } int Display( int a ) { cout<<"Base int display"<<endl; return 0; } }; class Derived : public Base { public: void Display( void ) { cout<<"Derived display"<<endl; } }; void main() { Derived obj; obj.Display(); obj.Display( 10 ); } $test1.cpp: In function ‘int main()’: test1.cpp:35: error: no matching function for call to ‘Derived::Display(int)’ test1.cpp:24: note: candidates are: void Derived::Display() On commenting obj.Display(10), it works.

    Read the article

  • C++ WIN32: Short multitasking example

    - by Con Current
    I searched for examples on how to create a simple multithreaded app that does something similar to this: #include <iostream> using namespace std; int myConcurrentFunction( ) { while( 1 ) { cout << "b" << endl; } } int main( ) { // Start a new thread for myConcurrentFunction while( 1 ) { cout << "a" << endl; } } How can I get the above to output a and b "randomly" by starting a new thread instead of just calling myConcurrentFunction normally? I mean: What is the minimal code for it? Is it really only one function I have to call? What files do I need to include? I use MSVC 2010, Win32

    Read the article

  • Why isn't the copy constructor elided here?

    - by Jesse Beder
    (I'm using gcc with -O2.) This seems like a straightforward opportunity to elide the copy constructor, since there are no side-effects to accessing the value of a field in a bar's copy of a foo; but the copy constructor is called, since I get the output meep meep!. #include <iostream> struct foo { foo(): a(5) { } foo(const foo& f): a(f.a) { std::cout << "meep meep!\n"; } int a; }; struct bar { foo F() const { return f; } foo f; }; int main() { bar b; int a = b.F().a; return 0; }

    Read the article

  • Convert c++ argument to int

    - by happyCoding25
    Hello, I have a small c++ program that needs to get and argument and convert it to an int. Here is my code so far: #include <iostream> using namespace std; int main(int argc,int argvx[]) { int i=1; int answer = 23; int temp; // decode arguments if(argc < 2) { printf("You must provide at least one argument\n"); exit(0); } // Convert it to an int here }

    Read the article

  • C++ enumaration

    - by asli
    Hi,my question is about enumaration,my codes are : #include<iostream> using namespace std; int main() { enum bolumler{programcilik,donanim,muhasebe,motor,buro} bolum; bolum = donanim; cout<<bolum<<endl; bolum+=2; /* bolum=motor */ cout<<bolum; return 0; } The output should be 1 3 but according to these codes the error is: error C2676: binary '+=' : 'enum main::bolumler' does not define this operator or a conversion to a type acceptable to the predefined operator Error executing cl.exe. 111.obj - 1 error(s), 0 warning(s) Can you help me ?The other question is what can I do if I want to see the output like that "muhasebe"?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >