Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
i m trying to run this piece of code i have written and i m getting this error.. DK why
i m working on windows 7 32 bit
my IDE is codeblocks and the compiler i m using is gcc
thanks for all the helpers
#include <conio.h>
#include <iostream>
//#include <vector>
using namespace std;
class A{
public:
int num[5];
void operator[](int x){
num[x]=3;
cout << num[x] <<<endl;
}
};
class B : public A{
public:
void func(){
(*this)[2];
}
};
int main(){
B b;
}
Please check this line
cout << num[x] <<<endl;
cout << num[x] <<<endl;
You have 3 < here instead of 2.
cout << num[x] <<<endl;
replace it with
cout << num[x] <<endl;
Remove the following character:
v
cout << num[x] <<<endl
^
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What is wrong with my code? I try to get a line break using both \n and endl but it shows an error.
#include <iostream>
using namespace std;
int main()
{
const int MinutesPerHour = 60;
const float PI = 3.14;
cout << MinutesPerHour;endl;
cout << PI;
return 0;
}
You should place the endl after the output stream operator <<.
Like this:
cout << MinutesPerHour << endl;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I'm a student who just learned to use C++ for a few weeks. I write C++ code on Code:: Block and I am trying to run this code to learn about vector:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
vector<int> intVector;
for(int i = 0; i < 10; i++)
{
intVector.push_back(i+1);
}
cout << "Numbers in vector: ";
for(int i = 0; i < intVector.size(); i++)
{
cout << intVector[i] + " ";
}
}
But the output is really weird:
Numbers in vector: vector::_M_emplace_back_auxector::_M_emplace_back_auxctor::_M_emplace_back_auxtor::_M_emplace_back_auxor::_M_emplace_back_auxr::_M_emplace_back_aux::_M_emplace_back_aux:_M_emplace_back_aux_M_emplace_back_aux
Process returned 0 (0x0) execution time : 0.047 s
Press any key to continue.
Does anyone know how to fix this problem? Do I use vector in the wrong way?
Try changing the cout line like this:
cout << intVector[i] << " ";
What you're trying to do is add an int& and a string literal -- in some compilers it will emit a warning indicating for you that you're not getting what you intended for.
For example with Clang:
warning: adding '__gnu_cxx::__alloc_traits>::value_type' (aka 'int') to a string does not append to the string [-Wstring-plus-int]
cout << intVector[i] + " ";
~~~~~~~~~~~~~^~~~~
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I was working on a problem for Project Euler using C++ in Code::Blocks 10.05 and found my program to be crashing in a strange place: the initialization. Here is a code snippet that reproduces the problem.
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
vector<deque<uint32_t> > f;
int main()
{
deque<uint32_t> p;
deque<uint32_t>::iterator dit1,dit2;
p.push_back(0);
p.push_back(1);
f.push_back(p);
cout << f.back().size() << endl;
cout << "f= ";
for(dit1==f.back().begin();dit1!=f.back().end();dit1++) cout << *dit1 << " ";
cout << "Checkpoint" << endl;
return 0;
}
Before posting here, I tried a test program to see if I could figure out the problem.
#include <iostream>
#include <deque>
#include <vector>
using namespace std;
int main(void)
{
uint64_t i;
deque<uint32_t> d;
vector<deque<uint32_t> > vd;
deque<uint32_t>::iterator it;
for(i=1;i<=5;i++) d.push_back(i);
vd.push_back(d);
for(it=vd.back().begin();it!=vd.back().end();it++) cout << *it << " ";
return 0;
}
The first program crashes while the second correctly reproduces the deque. Besides variable names, the only major difference I see is the first program uses a global variable and the test program uses a local variable. So why does the first program crash in the for loop while the second does not?
You used == instead of = in the for loop in the first program.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
What have I done wrong with the following code?
#include <iostream>
using namespace std;
main ()
{
int a;
int b;
int sum;
cout << "Enter first number \n";
cin >> a;
cout << "Enter second number \n";
cin >> b;
sum = a+b;
cout << "The sum of both numbers is" << sum << endl;
return 0;
}
Does the editor you are using tells errors, so the code is not executing? Or som exception rises? Or it is executing but nothing is shown? Please specify your problem accurately.
Anyway, you must use
int main ()
instead of
main()
Notice that your code returns a value. The last line of you code is:
return 0;
Thus, you must specify an int return type.
Check your initial lines with this.
#include <iostream>
using namespace std;
int main ()
{
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Whenever I try to run this program it returns an error saying:
no operator "<<" matches these operands
Also note that the program only runs into this problem in the getChoice() function.
#include <iostream>
#include "utilities.h"
using namespace std;
int getChoice(string inChoices[]){
int numOfChoices = sizeof(inChoices) / sizeof(inChoices[0]);
string x = inChoices[0];
string y = inChoices[1];
cout << x << endl << y << endl;
return numOfChoices;
}
int main()
{
string choices[2] = { "Happy Day", "Even Better Day" };
cout << utilities::getChoice(choices) << endl;
cout << endl << sizeof(choices) / sizeof(choices[0]) << endl;
}
You need also to include the string header:
#include <string>
You need to #include <string>
And your calculation of numOfChoices in getChoice() is wrong, since the parameter inChoices is actually a "pointer to string" instead of "array of strings".