Error in the following code

Dear Friends,
I am getting the following error when I integrate this piece of code into my program , but when I execute this independently It is executing fine so what could be the reason.

Error : error: expected unqualified-id before numeric constant
error: no match for ‘operator==’ in ‘fname == 65’
note: candidates are:
/usr/lib/gcc/i686-redhat-linux/4.6.3/../../../../include/c++/4.6.3/array:200:5: note: template<class _Tp, unsigned int _Nm> bool std::operator==(const std::array<_Tp, _Nm>&, const std::array<_Tp

[code]
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <algorithm>
using namespace std;

const string IFNAME = "wlan0"; -------> Error showing is here

int main()
{
ifstream input("/proc/net/wireless");
if(!input)
{
cout << "Couldn't open the file\n";
return 1;
}

string line;
while(getline(input, line)) {
istringstream bp(line);
string fname;
bp >> fname;
if(fname == IFNAME + ':')
{
replace(line.begin(), line.end(), '.', ' ');
cout << "first word: " << fname << '\n';
string word;
while(bp >> word)
cout << "next word: " << word << '\n';
}
}
}
[/code]
Last edited on
Which piece of code do you integrate and where is your program?!
Dear Friend,
why code tags are not working.
Please see the following code , this is the one which I used and giving the above errors.
[code]

const string IFNAME = "wlan0";
ifstream input("/proc/net/wireless");
if(!input)
{
cout << "Couldn't open the file\n ";
return 1;
}

string line;
while(getline(input, line)) {
istringstream bp(line);
string fname;
bp >> fname;
if(fname == IFNAME + ':') {
replace(line.begin(), line.end(), '.', ' ');
cout << "Interface Name: " << fname << '\n';

string word;
if(bp >> word)
cout << "Status: " << word <<'\n';
if(bp >> word)
i = atoi(word.c_str());
sr.rsp.states_rsp_list.push_back(i);
sr.rsp.states_rsp_list.push_back(i);
states_rsp_list.push_back(i);
cout << "Link_Channel_id: " << i << '\n';
if(bp >> word)

j = atoi(word.c_str());
lp.type = odtone::mih::link_param_802_11_rssi; lp.value = j;
sr.rsp.param_list.push_back(lp);
param_list.push_back(lp); cout << "Level_rssi_value: " << j << '\n';
if(bp >> word)
k = atoi(word.c_str());
cout << "noise: " << k << '\n';
sr.rsp.desc_rsp_list.push_back(11);
desc_rsp_list.push_back(11);
srl.push_back(sr);
}
[/code]
Till now I have not understood where is your code and what peace of code did you integrate.
But in any case the error refers to standard class std::array. I do not know why it refers to this class because you are uncapable to show clear where is your code and what piece of code did you integrate.
Dear friend ,
See the bellow code in that only you will understood in way I will explain ok. This code is the part of one switch case in my program , so this case code only giving the above error .

[code]

From here to

const string IFNAME = "wlan0"; -- --- Error is here "error: expected unqualified-id before numeric constant"

ifstream input("/proc/net/wireless");
if(!input)
{
cout << "Couldn't open the file\n ";
return 1;
}

string line;
while(getline(input, line)) {
istringstream bp(line);
string fname;
bp >> fname;
if(fname == IFNAME + ':') -----> Error :: error: no match for ‘operator==’ in ‘fname == 65’
{
replace(line.begin(), line.end(), '.', ' ');
cout << "Interface Name: " << fname << '\n';

string word;
if(bp >> word)
cout << "Status: " << word <<'\n';
if(bp >> word)

same code what I posted earlier only ok. Please see bellow one , after getting the position of status in /proc/wireless file , converting status into integer and then pushing into vector of structure name sr( status_response) . Similar to all parameter in wireless.h file like LEVEL and all I'm pushing .

i = atoi(word.c_str());
sr.rsp.states_rsp_list.push_back(i);
states_rsp_list.push_back(i);

cout << "Link_Channel_id: " << i << '\n';

if(bp >> word)

j = atoi(word.c_str());
lp.type = odtone::mih::link_param_802_11_rssi; lp.value = j;
sr.rsp.param_list.push_back(lp);
param_list.push_back(lp);

cout << "Level_rssi_value: " << j << '\n';

if(bp >> word)
k = atoi(word.c_str());

cout << "noise: " << k << '\n';

sr.rsp.desc_rsp_list.push_back(11);
desc_rsp_list.push_back(11);
srl.push_back(sr);
}

[/code]
It looks like IFNAME was defined somewhere as an integer constant equal to 65.
No IFNAME I were declared as "const string IFNAME = "wlan0"; " , but I don't know how come this error is coming
You declared IFNAME as string but somewhere in the code (maybe in some header) this name was declared some other way. Try to search every occurence of this name in used modules and headers.
Thank you , Yes you are correct , it is declare in " iwlib.h" header file ( wireless tools)
now it is working fine.
Topic archived. No new replies allowed.