I cannot compile a simple code as below using cygwin. I believe I am
using latest version of g++(3.3.1) I get following error
is_equal.cpp:9:19: ccc.cpp: No such file or directory
is_equal.cpp:11: error: `vector' was not declared in this scope
is_equal.cpp:11: error: parse error before `>' token
is_equal.cpp: In function `bool equal_vec(...)':
is_equal.cpp:12: error: `a' undeclared (first use this function)
is_equal.cpp:12: error: (Each undeclared identifier is reported only
once for
each function it appears in.)
is_equal.cpp:12: error: `b' undeclared (first use this function)
is_equal.cpp: In function `int main()':
is_equal.cpp:23: error: `vector' undeclared (first use this function)
is_equal.cpp:23: error: parse error before `>' token
is_equal.cpp:25: error: `cout' undeclared (first use this function)
is_equal.cpp:26: error: `cin' undeclared (first use this function)
is_equal.cpp:36: error: `v1' undeclared (first use this function)
is_equal.cpp:46: error: parse error before `>' token
is_equal.cpp:57: error: `v2' undeclared (first use this function)
is_equal.cpp:74:2: warning: no newline at end of file
/*
Vishal Pahuja
Lab 9 part 3
*/
#include <iostream>
#include <vector>
#include <stdexcept>
bool equal_vec(vector<int> a, vector<int> b)
{ if (a.size() !=b.size()) return false;
for (int i = 0;i<a.size();i++)
{
if (a[i] != b[i]) return false;
}
return true;
}
int main()
{ vector<int> v1;
int v1size;
cout << "\nHow many value you want to enter for vector v1?: \n";
cin >>v1size;
cout << "\nEnter values for vector v1: \n";
int i,j;
for (i = 0; i < v1size; i++)
{
cout << "Next: ";
//cin >> v1[i];
cin >> j;
v1.push_back(j);
}
cout << "\nVector v1 :\n";
for (i = 0; i < v1.size(); i++)
{
cout << v1[i]
<< "\n";
}
vector<int> v2;
int v2size;
cout << "\nHow many value you want to enter for vector v2?: \n";
cin>>v2size;
cout << "\nEnter values for vector v2: \n";
for (i = 0; i < v2size; i++)
{
cout << "Next: ";
//cin >> v2[i];
cin >> j;
v2.push_back(j);
}
cout << "\nVector v2 :\n";
for (i= 0; i< v2.size(); i++)
{
cout << v2[i]
<< "\n";
}
bool isequal;
isequal=equal_vec(v1,v2);
if (isequal) cout<< "The vectors are equal\n";
else cout<< "The vectors are not equal\n";
} 4 7106
Vish wrote: I cannot compile a simple code as below using cygwin. I believe I am using latest version of g++(3.3.1) I get following error
is_equal.cpp:9:19: ccc.cpp: No such file or directory is_equal.cpp:11: error: `vector' was not declared in this scope is_equal.cpp:11: error: parse error before `>' token is_equal.cpp: In function `bool equal_vec(...)': is_equal.cpp:12: error: `a' undeclared (first use this function) is_equal.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.) is_equal.cpp:12: error: `b' undeclared (first use this function) is_equal.cpp: In function `int main()': is_equal.cpp:23: error: `vector' undeclared (first use this function) is_equal.cpp:23: error: parse error before `>' token is_equal.cpp:25: error: `cout' undeclared (first use this function) is_equal.cpp:26: error: `cin' undeclared (first use this function) is_equal.cpp:36: error: `v1' undeclared (first use this function) is_equal.cpp:46: error: parse error before `>' token is_equal.cpp:57: error: `v2' undeclared (first use this function) is_equal.cpp:74:2: warning: no newline at end of file
/* Vishal Pahuja Lab 9 part 3 */
#include <iostream> #include <vector> #include <stdexcept>
bool equal_vec(vector<int> a, vector<int> b) { if (a.size() !=b.size()) return false; for (int i = 0;i<a.size();i++) { if (a[i] != b[i]) return false; } return true; }
int main()
{ vector<int> v1; int v1size; cout << "\nHow many value you want to enter for vector v1?: \n"; cin >>v1size;
cout << "\nEnter values for vector v1: \n"; int i,j;
for (i = 0; i < v1size; i++) { cout << "Next: "; //cin >> v1[i]; cin >> j; v1.push_back(j); } cout << "\nVector v1 :\n"; for (i = 0; i < v1.size(); i++) { cout << v1[i] << "\n"; }
vector<int> v2; int v2size; cout << "\nHow many value you want to enter for vector v2?: \n"; cin>>v2size;
cout << "\nEnter values for vector v2: \n"; for (i = 0; i < v2size; i++) { cout << "Next: "; //cin >> v2[i]; cin >> j; v2.push_back(j); }
cout << "\nVector v2 :\n"; for (i= 0; i< v2.size(); i++) { cout << v2[i] << "\n"; }
bool isequal; isequal=equal_vec(v1,v2);
if (isequal) cout<< "The vectors are equal\n"; else cout<< "The vectors are not equal\n";
}
vector is in the std namespace (as in cout). Put a "using namespace std;" after the includes
"Vish" <vi**********@hotmail.com> wrote in message
news:59**************************@posting.google.c om... I cannot compile a simple code as below using cygwin. I believe I am using latest version of g++(3.3.1) I get following error
is_equal.cpp:9:19: ccc.cpp: No such file or directory is_equal.cpp:11: error: `vector' was not declared in this scope is_equal.cpp:11: error: parse error before `>' token is_equal.cpp: In function `bool equal_vec(...)': is_equal.cpp:12: error: `a' undeclared (first use this function) is_equal.cpp:12: error: (Each undeclared identifier is reported only once for each function it appears in.) is_equal.cpp:12: error: `b' undeclared (first use this function) is_equal.cpp: In function `int main()': is_equal.cpp:23: error: `vector' undeclared (first use this function) is_equal.cpp:23: error: parse error before `>' token is_equal.cpp:25: error: `cout' undeclared (first use this function) is_equal.cpp:26: error: `cin' undeclared (first use this function) is_equal.cpp:36: error: `v1' undeclared (first use this function) is_equal.cpp:46: error: parse error before `>' token is_equal.cpp:57: error: `v2' undeclared (first use this function) is_equal.cpp:74:2: warning: no newline at end of file
/* Vishal Pahuja Lab 9 part 3 */
#include <iostream> #include <vector> #include <stdexcept>
bool equal_vec(vector<int> a, vector<int> b) { if (a.size() !=b.size()) return false; for (int i = 0;i<a.size();i++) { if (a[i] != b[i]) return false; } return true; }
int main()
{ vector<int> v1; int v1size; cout << "\nHow many value you want to enter for vector v1?: \n"; cin >>v1size;
cout << "\nEnter values for vector v1: \n"; int i,j;
for (i = 0; i < v1size; i++) { cout << "Next: "; //cin >> v1[i]; cin >> j; v1.push_back(j); } cout << "\nVector v1 :\n"; for (i = 0; i < v1.size(); i++) { cout << v1[i] << "\n"; }
vector<int> v2; int v2size; cout << "\nHow many value you want to enter for vector v2?: \n"; cin>>v2size;
cout << "\nEnter values for vector v2: \n"; for (i = 0; i < v2size; i++) { cout << "Next: "; //cin >> v2[i]; cin >> j; v2.push_back(j); }
cout << "\nVector v2 :\n"; for (i= 0; i< v2.size(); i++) { cout << v2[i] << "\n"; }
bool isequal; isequal=equal_vec(v1,v2);
if (isequal) cout<< "The vectors are equal\n"; else cout<< "The vectors are not equal\n";
}
you need to qualify all declarations from the c++ stardard headers with
"std::" or add the line "using namespace std;" before using them.
Wow. You guys rock....
Thanks. using namespace was the trick. I wonder why we were not told to use
it in out class. In class they always said, its your sweet will if you want
to say using namespace std. Well, Now I know...
Thanks again
Vish wrote: Wow. You guys rock....
Thanks. using namespace was the trick. I wonder why we were not told to use it in out class. In class they always said, its your sweet will if you want to say using namespace std. Well, Now I know...
Thanks again
You shouldn't put a using directive in a HEADER file. In a source file, after
all the includes, it shouldn't be a problem. Putting it in a header file can
seriously confuse the compiler.
Alternatively you could have said std::vector, std::cin, and std::cout This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: luigi |
last post by:
Hi,
I am trying to speed up the perfomance of stl vector by
allocating/deallocating blocks of memory manually. one version of the
code crashes when I try to free the memory. The other version...
|
by: Peng |
last post by:
Hi, I have encountered a simple but strange problem recently, with the STL
vector.
When I tried to compile a code like this, the compiler flags an error:
Error 212: "small.cc", line 200 #...
|
by: Joseph |
last post by:
I was doing my assignment,but encountered a problem at last step!!!!!!
for easy reading, i ommited lots of other things
//=====================code begin================================...
|
by: dd |
last post by:
Dears,
Can STL vector be a member in class, such as the following codes showed:
#ifndef __SB_SWLISTCTRL_H
#define __SB_SWLISTCTRL_H
class SBSWListCtrl : public wxListCtrl
{
public:...
|
by: LinuxGuy |
last post by:
Hi,
I have vector with some elements. now I want to search particular
element and find out the position of that element in that vector (
index ). I used find algorithm but it gives Iterator in...
|
by: Peterwkc |
last post by:
Hello all C++ expert programmer, i fairly new to C++ programming.
I have designed a matrix class which uses vector to store the data.
My problem is i want store the data into vector until user...
|
by: Hasan007 |
last post by:
The Program
This assignment will use separate compilation. You MUST use the following guidelines for the design of your program:
You are given the header file TelephoneList.h which contain the...
|
by: myusernotyours |
last post by:
Hi All,
Am working on a Java application in which I have to use the JNI to Interface with some native code for both windows and unix. Am using netbeans IDE with the C/C++ pack installed. Am also...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |