My compiler wrong?

M

Michael

Hi,

This is actually a continued post. I am soooo confused. Why do the
following codes not work? Could you please help me out? Or please tell
me whether it works for you. Then it should be a problem with my
complier.

Thanks a lot!!!
Michael

#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( int i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}
 
D

Default User

Michael said:
Hi,

This is actually a continued post. I am soooo confused. Why do the
following codes not work? Could you please help me out? Or please tell
me whether it works for you. Then it should be a problem with my
complier.

What do you mean, "not work"? We have no idea what your expectations
were, or what the code actually did.




Brian
 
K

Kai-Uwe Bux

Michael said:
#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( int i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}

works for me. output:

news_group> a.out
v[ 0 ] = 1
v[ 1 ] = 1
v[ 2 ] = 1
v[ 3 ] = 1
v[ 4 ] = 1
v[ 5 ] = 1
v[ 6 ] = 1
v[ 7 ] = 1
v[ 8 ] = 1
v[ 9 ] = 1


Best

Kai-Uwe Bux
 
D

Daniel T.

"Michael said:
Hi,

This is actually a continued post. I am soooo confused. Why do the
following codes not work? Could you please help me out? Or please tell
me whether it works for you. Then it should be a problem with my
complier.

Thanks a lot!!!
Michael

#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( int i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}

The output I got was:

v[ 0 ] = 1
v[ 1 ] = 1
v[ 2 ] = 1
v[ 3 ] = 1
v[ 4 ] = 1
v[ 5 ] = 1
v[ 6 ] = 1
v[ 7 ] = 1
v[ 8 ] = 1
v[ 9 ] = 1

Which is exactly what I was expecting to get.

What did you get? What were you expecting?
 
P

Pierre Barbier de Reuille

Michael said:
Hi,

This is actually a continued post. I am soooo confused. Why do the
following codes not work? Could you please help me out? Or please tell
me whether it works for you. Then it should be a problem with my
complier.

Thanks a lot!!!
Michael

#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( int i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}

Yep, it's working with my compiler and I don't see any problem :/
What is the error your compiler returns ?

Pierre
 
M

Michael

the error is
no matching function for call to `vector<int,allocator<int> >::at (int
&)'

thanks for all your help! something wrong with my compiler.

Thanks,
Michael
 
P

Pierre Barbier de Reuille

Michael said:
the error is
no matching function for call to `vector<int,allocator<int> >::at (int
&)'

thanks for all your help! something wrong with my compiler.

Thanks,
Michael
Just to check, try that :


#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( std::vector<int>::size_type i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}
 
M

Michael

Pierre said:
Just to check, try that :


#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( std::vector<int>::size_type i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}

Thanks for your help! It still did not work.

Michael
 
I

Ian Collins

Michael said:
the error is
no matching function for call to `vector<int,allocator<int> >::at (int
&)'

thanks for all your help! something wrong with my compiler.
Either the code you posted wasn't the code you compiled (why vector
rather std::vector in the error message?), or you should look for a
working compiler.
 
M

mathieu

Michael said:
Pierre said:
Just to check, try that :


#include <iostream>
#include <vector>

int main()
{

std::vector<int> v( 10, 1 );

for( std::vector<int>::size_type i = 0; i < 10; i++ )
{
std::cout << "v[ " << i << " ] = " << v.at(i);
std::cout << std::endl;
}
return 0;

}

Thanks for your help! It still did not work.


Are you *sure* you are executing the correct ./a.out. Delete it first
and compile your program again.

2 cents,
Mathieu
 
M

Michael

Thanks a lot for all your help!

I think there is something wrong with the compiler because it works
fine if I use v instead. I do appreciate your time and help!

Best Regards,
Michael
 
A

Alf P. Steinbach

* Michael:
I think there is something wrong with the compiler because it works
fine if I use v instead.


Is it possible to learn which version of which compiler you're using,
under which operating system?
 
M

Michael

Alf said:
Is it possible to learn which version of which compiler you're using,
under which operating system?

--

Sure. I am using Quincy99 on Windows XP.

Thanks,
Michael
 
T

Thomas J. Gritzan

Michael said:
Sure. I am using Quincy99 on Windows XP.

Quincy99 uses gcc 2.95.2, which seems to have problems with namespace std
and vector::at(). So it definitly is a compiler issue.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top