473,805 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cygwin vector problem

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(vecto r<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_v ec(v1,v2);

if (isequal) cout<< "The vectors are equal\n";
else cout<< "The vectors are not equal\n";
}
Jul 22 '05 #1
4 7132
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(vecto r<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_v ec(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

Jul 22 '05 #2

"Vish" <vi**********@h otmail.com> wrote in message
news:59******** *************** ***@posting.goo gle.com...
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(vecto r<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_v ec(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.
Jul 22 '05 #3
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
Jul 22 '05 #4
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

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
2977
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 seem to work. I would appreciate someone to comment on this. Version 1 (crashes on deallocating) #include <iostream>
8
1875
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 # Argument type 'char *' does not match expected parameter type 'const char (&)'. names.push_back(str); ^^^ can any one tell me why? Thanks.
13
2155
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================================ class Buyer{ void start(void); friend void Buyer_run(Buyer *buyer);
6
5210
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: HINSTANCE hdll;
6
9034
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 return. please help me to find out position of any element in that vector . any help is welcome Thanks
1
1186
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 is enough input. what i have did so far. Below is my program:
1
2303
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 function prototypes given below. Implements the function definitions in the implementation file TelephoneList.cpp. void displayList(const vector<string>& nameList, const vector<int>& teleNumList) : This function displays the name and the...
2
6667
myusernotyours
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 using Cygwin as my compiler (gcc), this is ostensibly because I hope this compiler will also compile the unix native libraries since I don't have a Linux installation. (I am working on a personal project from the office and can't get linux installed)....
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10368
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5544
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.