Visual C++ :: Compiler Error With Cout Object
Dec 15, 2012
I am asp.net C# developer. I decided to tackle C++, so I started today. This is probably something simple I am sure.
Code:
srand(static_cast<unsigned int>(time(0)));
int choice = rand() % NUM_WORDS;
string theWord = WORDS[choice][WORD];
string theHint = WORDS[choice][HINT];
[Code] ....
The error is happening on the last output operator, just before the jumble variable on the last line.The error is:
Code:
Intellisense: no operator"<<" matches these operands
operand types are: std::basic_ostream<char, std::char_traits<char> <<std::string
I understand what its saying, but jumble is a std::string
Here are my preprocessor directives and using statements
Code:
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
View 4 Replies
ADVERTISEMENT
Sep 20, 2012
class CPop {
CBSVector<CTour> pop;
CBSVector<double> probability;
int popsize;
double TotalFitness;
CTour Elite;
CTspGAParams GAParameters;
}
error C2059: syntax error : 'constant'
error C2238: unexpected token(s) preceding ';'
I don't know y these errors, it runs fine in simple c++ environment
View 14 Replies
View Related
Nov 11, 2013
Getting error: no operator "<<" matches these operands at line 36.
#include "stdafx.h"
#include <string>
#include <iostream>
#include <ostream>
using namespace std;
struct Date {
[Code] ....
View 8 Replies
View Related
Nov 9, 2013
Working on a basic class program and I'm generating two compiler errors that I'm not sure how to fix. Header file, implementation cpp and main cpp are shown below. The specific errors are shown after the code.
Header file Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
[Code].......
The file generates the second error, C2228, at lines 37-41 and 43. Basically where I tried using the second created object. Error message is "left of '.setFirstName' must have class/struct/union"
View 8 Replies
View Related
Nov 29, 2013
Working on a solution involving inheritance. The whole solution is pretty massive at this point so I'll just focus on the problem areas. I'm getting a lot of "redefinition" and "undefined class type" compiler errors, including C2370, 2011, 2504, and 2027, in Benefit.h, Employee.h (the constant members are a big occurance) I'm also getting 2027 and 2079 in EmployeeMain.cpp. with my Benefit and Employee object calls.
Clearly I missed something in about how to code this correctly. Sadly the course textbook focuses on general OOP theory instead on the accompanying C++ syntax.
Benefit.h
Code:
#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
using namespace std;
[Code] .....
View 4 Replies
View Related
Jul 30, 2013
My compiler (GCC) keeps expecting an expression where it shouldn't in 1 specific piece of my code:
int zxcNewWindow( HWND parent, TCHAR *text, zxWINDOW *kid,
UINT style, int x, int y, int w, int h, int type )
// right here
{
*kid = zxDefWINDOW;
The project contains only 2 files right now and the settings are just the default for an empty Code::Blocks 12.11 project. Both files are in UTF-8 format (tried in ASCII too), I just cannot see why this is not compiling correctly. I'll post the files in the next two posts.
Edit: For those of you who didn't get what the error was from the above here's the full log:
mingw32-gcc.exe -Wall -g -DzxDEBUG -c C:MePrjscppzxGUImain.c -o objmain.o
C:MePrjscppzxGUImain.c: In function 'zxcNewWindow':
C:MePrjscppzxGUImain.c:39:10: error: expected expression before '{' token
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings (0 minutes, 0 seconds)
View 8 Replies
View Related
May 20, 2014
I am trying to run this source code but i am getting the compiler error Expression Must Have a Constant Value. I tried making both the variables x and y constants and assigned them to a significantly big number but then i am getting the error expression must be a modifiable lvalue.I have made comments in the code in front where Visual Studio is giving me the syntax error (red squiggly line).
#include<iostream>
#include <string>
#include<cmath>
using namespace std;
int main(){
int x;
int y;
[Code] ......
View 3 Replies
View Related
Oct 15, 2014
I am having problems compiling this program. line 29 causes the error "left operand must be l-value".
// chap5proj.cpp : Defines the entry point for the console application.
//
# include <stdafx.h>
# include <iostream>
using namespace std;
int main() {
double mph, time, disPerHour, milesTrav;
[code]....
View 2 Replies
View Related
Jun 8, 2013
in c program what is the difference between a compiler error and a warning
View 1 Replies
View Related
Apr 13, 2013
I'm making a very first program. It's very little more then a simplistic calculator, but i'm having a problem with the cout function. It won't display any text what could the reasons be?
#include <iostream>
#include <string>
#include <sstream>
using namespacestd;
int main () {
do {
int(a);
[Code]...
Oh and i'm aware it's still riddled with numerous problems, I just have been working on the cout thing first.
View 3 Replies
View Related
May 12, 2013
Full disclosure: this is an exercise from "Sams Teach Yourself C++ in 24 Hours" by Jesse Liberty and Rogers Candenhead. This refers to Chapter 9 (Hour 9 Activity 1)
I created a class called Point, in Point.h
I created a class called Rectangle in Rectangle.h and Rectangle.cpp
If I create an int main() function in Rectangle.cpp (that includes Rectangle.h), I can compile Rectangle.cpp and run the resulting program. Fine.
Question:
I create a separate file called main.cpp. I include Rectangle.h. But now the compiler complains.
Code:
$ g++ main.cpp -o main
/tmp/cc38JIph.o: In function `main':
main.cpp:(.text+0x26): undefined reference to `Rectangle::Rectangle(int, int, int, int)'
main.cpp:(.text+0x32): undefined reference to `Rectangle::getArea() const'
collect2: ld returned 1 exit status If I can create a class in Point.h and use it in Rectangle.h, why can I not just use Rectangle in main.cpp?
And the files, of course:
file: main.cpp
Code:
#include <iostream>
#include "Rectangle.h"
using std::cout;
using std::endl;
[Code] .....
View 3 Replies
View Related
Nov 1, 2013
Well, I thought I had this program working but now I'm getting the above referenced compiler error. The program is just a basic user interface. It is for a classwork assignment.
The program is to accept user information as a string, convert it (if needed) to either the int or double variable, and then display the result. I'm using stringstream convert to make the change between types, but I'm not sure if I'm using it right (that might be what's causing the error, I'm not sure). Line 36-37 generates the error.
Code:
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
[Code] ....
View 5 Replies
View Related
May 18, 2014
I'm trying to compile this code which is a header file.
#ifndef CUBEMAP_H_INCLUDED
#define CUBEMAP_H_INCLUDED
#include "Texture.h"
#include <string>
class CubeMap : Texture {
[Code] ....
But I get the following error:
|9|error: expected ')' before 'Directory'|
How can i resolve this?
View 6 Replies
View Related
Dec 10, 2014
Having issues with program to create a shape area calculator with circle square and rectangle. the uml goes as follows:
Where the UML has shape as the abstract class with public area():double, getName():string,and getDimensions:string, rectangle derived from shape with protected height, and width, and a public rectangle(h:double, w:double), followed by a derived square from rectangle with just a public square(h:double), and finally a circle derived from shape with a private radius, and a public circle(r:double).
[URL]
Have linked my program and it is giving me the following compiler errors:
error: 'qdebug' was not declared in this scope line 15 of main
error: cannot declare variable 'shp' to be of abstract type 'shape' line 22 of main
error: expected primary-expression before ')' token lines 29 -31 of main
(note previously had qstring as a header file yet changed to string since I was getting error qstring was not declared in this scope.)
View 5 Replies
View Related
Feb 13, 2014
I need to reverse this loop. get how to do it in order but when i have to reverse it i get a compiler error
int main() {
cout << "Enter 3 cities" << endl;
string cities;
for ( int i = 0; i < 3; ++i ) {
getline(cin, cities[3];
[Code] ....
View 2 Replies
View Related
Oct 31, 2012
I am trying to compile the files file1.c and file2.c using Mingw (gcc)
/////////////////////
header.h
////////////////////
#ifndef header
#define header
int variable;
#endif
[Code] ....
I would have expected a multiple defnition error when linking the two .c files. as in both the files, with the 'int variable' command, the variable 'variable' is defined (memory allocated) and during linking the linker doesnot know which variable to link to.
I get an error though when i use "int variable =123;" in the header file instead of the "int variable;" statement. i dont understand as in both the cases the variable is defined (memory is allocated) and the linker should give a multiple definition error.
View 8 Replies
View Related
Oct 8, 2014
Here is my code,
Code:
class A {
public:
void display() {
cout<<"A"<<endl;
[Code] .....
The compiler error is "error C2039: 'display' : is not a member of 'SP<T>'". What am I missing here?
View 14 Replies
View Related
Jun 5, 2013
I have been implementing a Hash Table class made, and ran into a bit of a problem in my Delete function. I have the hash table made up as
vector<list<HashNode<T,X>>> m_Table
My problem is when I iterate through the vector, and then the list in that current element to try and find the Node I want to delete, the STL list class gives me the error:
Error1error C2678: binary '==' : no operator found which takes a left-hand operand of type 'HashNode<T,X>' (or there is no acceptable conversion)
Here's the Delete function:
template <typename T, typename X>
void HashTable<T,X>::Delete(T key) {
HashNode<T,X> Node;
HashNode<T,X> NodeTemp;
list<HashNode<T,X>> temp;
list<HashNode<T,X>>::iterator it;
vector<list<HashNode<T,X>>>::iterator iter;
[Code] ....
Why it's not letting me do the .Remove() function?
View 3 Replies
View Related
Jan 30, 2015
Error message is identifier expected and declaration terminated incorrectly.
//to define a class Employee
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
class cEmp {
[code]....
View 7 Replies
View Related
Jan 24, 2014
I use a SEH handler in my code, like this:
__try
{
.. Some codes ...
}
__except(
EXCEPTION_EXECUTE_HANDLER
)
{
TRACE(_T("Exception"));
}
but get the following compiler errors:
1>e: est.cpp(3310): warning C4509: nonstandard extension used: 'CMyClass::Test' uses SEH and 'iterator' has destructor
1> e: est.cpp(3290) : see declaration of 'iterator'
e: est.cpp(3450): error C2712: Cannot use __try in functions that require object unwinding
View 2 Replies
View Related
Mar 18, 2014
I have a project that is essentially a hot pot of C/asm (naked functions etc). The code gets injected into another EXE. It works fine when compiled in Visual C++ 6 but when compiled in Visual Studio 2008 it compiles fine but falls over in use.
Are there certain settings I need to look out for? I have optimization disabled and as far as I can tell the command line options for compiler/linker are the same (given the differences).
I have opened both builds in IDA and the 2008 build has more import and offset jumps are in different places.
View 1 Replies
View Related
Oct 17, 2013
main:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include "Board.cpp"
int main(int argc, char* argv[]){
argc=5;
argv[argc];
[Code] .....
I can't find a place where there are two definitions of any of the Board methods
View 9 Replies
View Related
Mar 4, 2014
Write a program that computes how many feet an object falls in 1 second, 2 seconds, etc., up to 12 seconds.
1.Have a procedure called FallingDistance which has one input parameter, seconds, and one output parameter, distance.
2. Compute the distance in feet an object falls using this formula: d = ½ gt2
(where g = 32.2)
3. The main program should call FallingDistance within a loop which passes the values 1 through 12 as arguments.
4. Print a table with seconds and falling distance in feet.
Sample Output (This program has no input)
Seconds Distance
================
1 16.1000
2 64.4000
3 144.9000
4 257.6000
5 402.5000
6 579.6000
7 788.9000
8 1030.4000
9 1304.1000
10 1610
11 1948.1000
12 2318.4000
In C++, the procedure is called a function. Instead of using an output parameter, your C++ function FallingDistance should return a result of type double. This is what I created:
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
const double g =32.2;
double fallingDistance(double);
[Code] ....
which gave me this error:
1>------ Build started: Project: Lab 6, Configuration: Debug Win32 ------
1> Source.cpp
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(27): error C2065: 'fallingdistance' : undeclared identifier
1>c:usershanahdocumentsschoolprogamming ilab 6lab 6source.cpp(36): error C2065: 't' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
View 4 Replies
View Related
Nov 23, 2013
Code:
#include <Data.h>
int main(int arg_count, char** argv) {
if(arg_count!=3){
cerr<<"Files misisng
";
exit(1);
[code]...
This actually should work, because it is passing address of polymorphisms object.I have tried changing prototype of test in Data.h, but failed.passing object address/pointers in C++.
View 5 Replies
View Related
Nov 24, 2013
Code:
class Main{
class B b_obj;
C c_obj=b_obj.test("some",89); // I cannot get this done.!
}
Below are .h files:
class B{
public:
C* test(const char *, int); /// this doesn't work
constructor
//member variables
[Code] ....
However, map<string, vector<bol>> test(const char *, int); works.I know second thing will work, but how to take reference of class object?
I have include .h file in main, B and C, wherever it is required.
View 4 Replies
View Related
Dec 21, 2012
This is my question : Define a class named HOUSING in C++ with the following descriptions:
Private members
REG_NO integer(Ranges 10 - 1000)
NAME Array of characters(String)
TYPE Character
COST Float
Public Members
-Function Read_Data( ) to read an object of HOUSING type
-Function Display() to display the details of an object
-Function Draw Nos( ) to choose and display the details of 2 houses selected randomly from an array of 10 objects of type HOUSING Use random function to generate the registration nos. to match with REGNO from the array.
Now I' trying to do this by this way
Code:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
class housing {
private:
int REG_NO;
char NAME[10];
[Code] .....
I am trying to pass the entire array of object in DrawNos(). but getting compilation error -
32: 'housing:rawNos(housing * *)' is not a member of 'housing'
48: Structure required on left side of . or .*
What is the problem? How can I pass the array of object in function and use it.
View 3 Replies
View Related