Hello everybody! I'm trying to display the result of difference of two-dimensional vectors using friend overloading. Builder shows the following error after compilation (line 40). What should I change for in my code in order to find the problem? Thanks in advance. **[C++ Error] 05_Part.cpp(40): E2034 Cannot convert 'double' to 'Vector2D'** #include <iostream.h> #include <conio.h> class Vector2D { double x, y; friend Vector2D operator- ( const Vector2D &, const Vector2D & ); public: friend ostream & operator << (ostream & os, const Vector2D & cv) { os << cv.x << ',' << cv.y; return os; } }; Vector2D operator- ( …

Member Avatar
Member Avatar
+0 forum 4

Hello everybody! I'm trying to display the result of addition of vectors. But Builder shows the error after compilation (line 29). What should I change for in my code in order to find the problem? Thanks in advance. #include <iostream.h> #include <iomanip.h> #include <conio.h> class CVector2D { public: CVector2D(double x0 = 0, double y0 = 0) :x(x0), y(y0) { } double x, y; CVector2D const operator +(CVector2D const& vector2)const { return CVector2D(x + vector2.x, y + vector2.y); } }; using namespace std; int main() { CVector2D a(3.0, 5.8); CVector2D b(7.3, 8.8); CVector2D c = a + b + CVector2D(3, 9); …

Member Avatar
Member Avatar
+0 forum 2

Dear Kind DaniWebbers, I am trying to overload the fstream operators (ofstream/ifstream), so that I can save a class to a 'Binary' file and also display it with cout. But the ways in which each need to be implemented is different. Please can you show me how to define different operators for each. Here is my test class: class CBase { public: //CBase(void) {}; CBase(int i = 0, float f = float(0.0), double d = double(0.0), char c = 'A') : iMyInt(i), fMyFloat(f), dMyDouble(d), cMyChar(c) {} ~CBase(void) {} int iMyInt; float fMyFloat; double dMyDouble; char cMyChar; friend std::ostream& operator<<(std::ostream& os, …

Member Avatar
Member Avatar
+0 forum 4

#include <iostream> int main () { cout <<"***\n"; return 0; } just an idea ... it is a short code but anyway it doesn't work (i just started c++ and i have dev c++ 4.9.9.2 c) cout isn't working

Member Avatar
Member Avatar
+0 forum 5

want to change all printf to cout with keeping the same output #include <iostream> using namespace std;Heading Here void main() { unsigned int a,b,c; char*format1 , *format2; format1 = "%04x%s%04x=%04x \n"; format2 = "%c%04x=%04x \n"; a = 0x0ff0; b = 0xf00; c=a>>4; printf (format1,a,">>",4,c); c=a&b; printf (format1,a,"&",b,c); c=a|b; printf (format1,a,"|",b,c); c=a^b; printf (format1,a,"^",b,c); c=~a; printf (format1,a,"~",b,c); system("Pause"); }

Member Avatar
Member Avatar
+0 forum 1

Could someone please help me find out what the problem is with this simple program? This souldn't be happening. Here is the code: #include "stdafx.h" using namespace std; int main () { int numbers[5]; int * p; p = numbers; *p = 10; p++; *p = 20; p = &numbers[2]; *p = 30; p = numbers + 3; *p = 40; p = numbers; *(p+4) = 50; for(int n=0; n<5; n++) { cout<<numbers[n]<<", "; } return 0; } Here is the comiler error: *test.cpp(23): error C2065: 'cout' : undeclared identifier* I'm using Visual C++ Express Edition.

Member Avatar
Member Avatar
+0 forum 2

Hello, I have the following code: `#include <iostream.h> void main() { double test=3.46578953218549; cout.setf(ios::dec); cout<<test; }` I understand that iostream.h is outdated and Microsoft Visual Studio has iostream. However, When I remove the ".h" the setf, ios, etc, line 6 has multiple errors. So, my question is: How do I set the number of decimal places without having "setprecision(51)" in every cout line, as such: `#include <iostream.h> void main() { double test=3.46578953218549; cout<<std::setprecision(51)<<test; }` Or, where can I download iostream.h? Joe

Member Avatar
Member Avatar
+0 forum 6

How to make a program that prints out 10 stars with using cout or for loops or while loops.

Member Avatar
Member Avatar
+0 forum 6

Well... im making some kind of graphic engine for console in [B]c++[/B], ASCII based, just for exercise... anyways, i was wandering, can i print text [B]faster[/B]? Right now i'm printing the whole map of characters (pix[160][120]) in a [B]single line[/B], so it is fast, however i need it faster cause the screen is [B]flickering[/B] and it is realy annoying.. help please? im kind of newbie to console input output streaming..

Member Avatar
Member Avatar
+0 forum 7

Hi all, I am trying to create a class to serve as a customized cout class. Right now I have made some test code to see if I can do it. Right now I am trying to make it function just like cout, but later I will have it do more than just print text to the screen. Currently my class works when I try and print one item, but not multiple ones. The code: [CODE=c++, operator.cpp]#include "operator.h" using namespace std; void printclass::operator<<( const string & mesg ) { cout << mesg; } int main() { printclass print; print << …

Member Avatar
Member Avatar
+0 forum 2

can u help me convert the cout to printf..i dont have a clue how.. tnx [CODE]#include<iostream.h> #include<string.h> #include<conio.h> int findSimilar(char[],char[]); void checkValue(int,int); int main(){ char boy[50]; char girl[50]; int similarInBoy=0; int similarInGirl=0; int total; clrscr(); cout<<"Enter Boy's Name: "; cin.getline(boy,50); cout<<"Enter Girl's Name: "; cin.getline(girl,50); similarInBoy=findSimilar(boy,girl); similarInGirl=findSimilar(girl,boy); total=similarInGirl+similarInBoy; cout<<"Boy: "<<similarInBoy<<","; checkValue(similarInBoy,1); cout<<"\n"; cout<<"Girl: "<<similarInGirl<<","; checkValue(similarInGirl,2); cout<<"\n"; cout<<"Total: "<<total<<","; checkValue(total,3); cout<<"\n"; getch(); return 0; } void checkValue(int similar,int gender){ if(gender==1){ if(similar>6) similar%=6; switch(similar){ case 1: cout<<"Friend"; break; case 2: cout<<"Love"; break; case 3: cout<<"Affair"; break; case 4: cout<<"Married"; break; case 5: cout<<"Enemy"; break; case 6: cout<<"Sweetheart"; break; } } else if(gender==2){ …

Member Avatar
Member Avatar
+0 forum 6

Hi all! I have a little problem here, I would like the width function in cout applied to all the sucesive outputs. However, it is only applied to the next output only, I mean, with this code I get 0:00:10:20:30:4 1:01:11:21:31:4 2:02:12:22:32:4 3:03:13:23:33:4 4:04:14:24:34:4 5:05:15:25:35:4 6:06:16:26:36:4 7:07:17:27:37:4 8:08:18:28:38:4 9:09:19:29:39:4 and I would like 0:0 0:1 0:2 0:3 0:4 1:0 1:1 1:2 1:3 1:4 2:0 2:1 2:2 2:3 2:4 3:0 3:1 3:2 3:3 3:4 4:0 4:1 4:2 4:3 4:4 5:0 5:1 5:2 5:3 5:4 6:0 6:1 6:2 6:3 6:4 7:0 7:1 7:2 7:3 7:4 8:0 8:1 8:2 8:3 8:4 9:0 9:1 …

Member Avatar
Member Avatar
+0 forum 5

Hello everyone. I am working on my final project at university for C++, and I got stuck a little. I have an array inside an array. And I want to access that inner array's member and print it with cout. Here is the code: [code=c] void standings(userClub uc){ cout << endl; cout << "First Division" << endl; int table[10]; for(int i=0; i<=9; i++){ table[i] = coms[i].pts; } table[9]=uc.pts; sort(table, table+10); int y=9; while(y>=0){ cout << table[coms[y].name] << "\t"; // HERE I WANT TO ACCESS cout << table[y] << endl; // coms array y--; } } [/code] Please have in mind …

Member Avatar
Member Avatar
+0 forum 3

Hi! I've recently converted some C code to a bit more native C++. This included changing printf() statements to std::cout statements. However, some printf()'s are rather lengthy and annoyingly long (and human-error-prone) to write in std::cout. Example (and this one is a short one): C-style: [CODE]printf("ERROR %d: %s: %s\n", event, origin ? origin : "?", fulltext.c_str());[/CODE] C++-style: [CODE]std::cout << "ERROR " << event << ": " << origin ? origin : "?" << ": " << fulltext << "\n";[/CODE] I personally find the first way much more clear and easier to write. What is the recommended way to do this …

Member Avatar
Member Avatar
+0 forum 4

Hey guys, This is my first official post on DaniWeb :) I am new at programming in C++ using visual studios, and right now I am fooling around with storing user input into Arrays. I am having a problem with my code, using an array size of 3 to store the users input into the first 2 spots [0 and 1] and then making a calculation in the 3rd spot[2]. Here is my code: [CODE]#include <iostream> using namespace std; int main() { double userInput[3]; //array can only hold *3* elements cout<<"Enter the number of cars you wish to buy: "; …

Member Avatar
Member Avatar
+0 forum 4

hello there I was wondering how would we print numbers like xxxxxxxx.xxxx using cout? I know we can use setprecision() to get the decimals right to the dot. But i am looking to print the numbers left to the dot.ex: 00000012.12345 is there a way that i am unaware about it? please let me know.

Member Avatar
Member Avatar
+0 forum 1

Recently I was assigned to create a program driven by a main menu, followed by a submenu, followed by functions. Below is an attempt of mine, which does display the main menu, and from there a user must enter a value to proceed to a second menu, however it doesn't seem to work, is there anybody that can help? NOTE: The program is far from complete, so the only choice available is "1", which will select the distance conversion, but my problem is that it won't display on the screen, when it does, it should have more options. [CODE] #include …

Member Avatar
Member Avatar
+0 forum 4

Hi, Recently (today) got an assignment to take a particular code that we've done previously, and split it into 3 files: 2 .cpp files and a header file. Now, i believe i've done it correctly, but the only thing that's throwing up errors is the use of friend for overloading the << operator. Here's how it was used in the previous example (class name is "complex"): [CODE] ...//other class stuff friend ostream & operator<<(ostream &os, const complex &z); }; //end of class ostream & operator<<(ostream &os, const complex &z) { //..stuff... } [/CODE] and I've split the class declaration and …

Member Avatar
Member Avatar
+0 forum 4

hi im working on a project for uni. i am doin a games software development course and i am currently working on a small game. we have to then optimise it so it runs as fast as it can to prevent lag. though im getting alot of bottlenecks around cout statments. i was wondering if there is a alternative to using cout with doesnt access as many of the registars when you get down to the assembler level of the program as this is where it realy solws down. i am using visual c++ express i can include and libarys …

Member Avatar
Member Avatar
+0 forum 2

I guess i'm missing something basic, but i'm new to C++ and do not know how do these streams behave. Can someone please explain why no text is printed to the screen in the following example: [code=C++] #include <iostream> using namespace std; int main (void) { char *ptr = NULL; cout << ptr << "This is a sample text." << endl; return 0; } [/code]

Member Avatar
Member Avatar
+0 forum 3

The End.