C++ language and <ios> include file

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Dmitry R
New poster
Posts: 7
Joined: Sat Sep 17, 2005 10:42 am
Contact:

C++ language and <ios> include file

Post by Dmitry R » Sun Aug 20, 2006 8:20 pm

How does it come that the C++ compiler cannot find the <ios> header file from STL?

Here is a program I sent to the Judge:

Code: Select all

#include <iostream>
#include <ios>
#include <cstdio>
#include <iomanip>

const int MAX = 101;
int field[MAX][MAX];
bool used[MAX];

int main(void)
{
	while (true)
	{
		static int count = 0;
		int x, y;
		std::cin >> x >> y;
		if (!x && !y)
			return 0;
		for (int i = 0; i < MAX; ++i)
		{
			used[i] = false;
			for (int j = 0; j < MAX; ++j)
				field[i][j] = 0;
		}
		while (x || y)
		{
			used[x] = used[y] = true;
			field[x][y] = 1;
			std::cin >> x >> y;
		}
		for (int i = 1; i < MAX; ++i)
			for (int j = 1; j < MAX; ++j)
				for (int k = 1; k < MAX; ++k)
					if (field[j][i] > 0 && field[i][k] > 0)
					{
						if (field[j][k] == 0 || field[j][k] > field[j][i] + field[i][k] )
							field[j][k] = field[j][i] + field[i][k];
					}
		int res = 0;
		for (int i = 1; i < MAX; ++i)
		{
			if (!used[i])
				continue;
			for (int j = 1; j < MAX; ++j)
				if (i != j && used[j])
					res += field[i][j];
		}
		int num = 0;
		for (int i = 1; i < MAX; ++i)
			num += used[i];
		std::cout << std::fixed;
		std::cout << std::setprecision(3);
		std::cout << "Case " << ++count << ": average length between pages = " << static_cast<double>(res) / (num*(num - 1)) << " clicks" << std::endl;
		/*printf("Case %d: average length between pages = %.3f clicks\n", ++count, static_cast<double>(res) / (num*(num - 1)));*/
	}
}
And this is the report from Judge:

Code: Select all

Here are the compiler error messages:

04850924_24.c:2: ios: No such file or directory

User avatar
Carlos
System administrator
Posts: 1286
Joined: Sat Oct 13, 2001 2:00 am
Location: Valladolid, Spain
Contact:

Post by Carlos » Sun Aug 20, 2006 11:11 pm

Is ios a proper file to add? I've never heard about it....isn't it included in iostream?
DON'T PM ME --> For any doubt, suggestion or error reporting, please use the "Contact us" form in the web.

Dmitry R
New poster
Posts: 7
Joined: Sat Sep 17, 2005 10:42 am
Contact:

Post by Dmitry R » Sun Aug 20, 2006 11:33 pm

Carlos wrote:Is ios a proper file to add? I've never heard about it....isn't it included in iostream?
Maybe it is. But even without it, there is another problem

Code: Select all

#include <iostream>
#include <iomanip>

const int MAX = 101;

int field[MAX][MAX];

bool used[MAX];

int main(void)
{
	while (true)
	{
		static int count = 0;
		int x, y;
		std::cin >> x >> y;
		if (!x && !y)
			return 0;
		for (int i = 0; i < MAX; ++i)
		{
			used[i] = false;
			for (int j = 0; j < MAX; ++j)
				field[i][j] = 0;
		}
		while (x || y)
		{
			used[x] = used[y] = true;
			field[x][y] = 1;
			std::cin >> x >> y;
		}
		for (int i = 1; i < MAX; ++i)
			for (int j = 1; j < MAX; ++j)
				for (int k = 1; k < MAX; ++k)
					if (field[j][i] > 0 && field[i][k] > 0)
					{
						if (field[j][k] == 0 || field[j][k] > field[j][i] + field[i][k] )
							field[j][k] = field[j][i] + field[i][k];
					}
		int res = 0;
		for (int i = 1; i < MAX; ++i)
		{
			if (!used[i])
				continue;
			for (int j = 1; j < MAX; ++j)
				if (i != j && used[j])
					res += field[i][j];
		}
		int num = 0;
		for (int i = 1; i < MAX; ++i)
			num += used[i];
		std::cout << std::fixed;
		std::cout << std::setprecision(3);
		std::cout << "Case " << ++count << ": average length between pages = " << static_cast<double>(res) / (num*(num - 1)) << " clicks" << std::endl;
	}
}
This code receives another CE:

Code: Select all

Here are the compiler error messages:

04851224_24.c: In function `int main()':
04851224_24.c:51: `::fixed' undeclared (first use here)
Well, it seems weird for me because lots of people are submitting problems in C++ without any problems... Am I making a mistake somewhere?

Moha
Experienced poster
Posts: 216
Joined: Tue Aug 31, 2004 1:02 am
Location: Tehran
Contact:

Post by Moha » Mon Aug 21, 2006 12:02 am

for UVA you should use cout.setf(ios::fixed) and cout.precision(3).

Dmitry R
New poster
Posts: 7
Joined: Sat Sep 17, 2005 10:42 am
Contact:

Post by Dmitry R » Mon Aug 21, 2006 12:11 am

Moha wrote:for UVA you should use cout.setf(ios::fixed) and cout.precision(3).
Thank you very much. I'll do.

stevejack
New poster
Posts: 1
Joined: Fri Sep 11, 2009 11:23 am

Re: C++ language and <ios> include file

Post by stevejack » Fri Sep 11, 2009 11:46 am

he ios class maintains formatting and error state information for streams. TPF announced support for the STL port standard template library (STL) with ANSWER: TPF supplies external header files for each I/O stream class. The C++ compiler will find the C header that matches.
Mind Game....

alexdwsn12
New poster
Posts: 2
Joined: Fri Jun 18, 2010 3:12 pm

Re: C++ language and <ios> include file

Post by alexdwsn12 » Fri Jun 18, 2010 3:20 pm

The <ios> is used in C++. It handles the input and output operations. It consists of libraries, functions and variables. You write cin or cout keyworks, these keywords operation is handled by the <ios> include file. So it is very essential for C++ programming. Without it, it will display error.

Post Reply

Return to “C++”