Why when I wan to compile the following multi thread merge sorting C program, I receive this error:
ap@sharifvm:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpthread
mer.c:4:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
ap@sharifvm:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpthread
mer.c:4:22: fatal error: iostream.h: No such file or directory
#include <iostream.h>
^
compilation terminated.
My program:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <iostream>
using namespace std;
#define N 2 /* # of thread */
int a[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; /* target array */
/* structure for array index
* used to keep low/high end of sub arrays
*/
typedef struct Arr {
int low;
int high;
} ArrayIndex;
void merge(int low, int high)
{
int mid = (low+high)/2;
int left = low;
int right = mid+1;
int b[high-low+1];
int i, cur = 0;
while(left <= mid && right <= high) {
if (a[left] > a[right])
b[cur++] = a[right++];
else
b[cur++] = a[right++];
}
while(left <= mid) b[cur++] = a[left++];
while(right <= high) b[cur++] = a[left++];
for (i = 0; i < (high-low+1) ; i++) a[low+i] = b[i];
}
void * mergesort(void *a)
{
ArrayIndex *pa = (ArrayIndex *)a;
int mid = (pa->low + pa->high)/2;
ArrayIndex aIndex[N];
pthread_t thread[N];
aIndex[0].low = pa->low;
aIndex[0].high = mid;
aIndex[1].low = mid+1;
aIndex[1].high = pa->high;
if (pa->low >= pa->high) return 0;
int i;
for(i = 0; i < N; i++) pthread_create(&thread[i], NULL, mergesort, &aIndex[i]);
for(i = 0; i < N; i++) pthread_join(thread[i], NULL);
merge(pa->low, pa->high);
//pthread_exit(NULL);
return 0;
}
int main()
{
ArrayIndex ai;
ai.low = 0;
ai.high = sizeof(a)/sizeof(a[0])-1;
pthread_t thread;
pthread_create(&thread, NULL, mergesort, &ai);
pthread_join(thread, NULL);
int i;
for (i = 0; i < 10; i++) printf ("%d ", a[i]);
cout << endl;
return 0;
}
Why when I wan to compile the following multi thread merge sorting C program, I receive this error:
ap@sharifvm:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpthread
mer.c:4:20: fatal error: iostream: No such file or directory
#include <iostream>
^
compilation terminated.
ap@sharifvm:~/forTHE04a$ gcc -g -Wall -o mer mer.c -lpthread
mer.c:4:22: fatal error: iostream.h: No such file or directory
#include <iostream.h>
^
compilation terminated.
My program:
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <iostream>
using namespace std;
#define N 2 /* # of thread */
int a[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; /* target array */
/* structure for array index
* used to keep low/high end of sub arrays
*/
typedef struct Arr {
int low;
int high;
} ArrayIndex;
void merge(int low, int high)
{
int mid = (low+high)/2;
int left = low;
int right = mid+1;
int b[high-low+1];
int i, cur = 0;
while(left <= mid && right <= high) {
if (a[left] > a[right])
b[cur++] = a[right++];
else
b[cur++] = a[right++];
}
while(left <= mid) b[cur++] = a[left++];
while(right <= high) b[cur++] = a[left++];
for (i = 0; i < (high-low+1) ; i++) a[low+i] = b[i];
}
void * mergesort(void *a)
{
ArrayIndex *pa = (ArrayIndex *)a;
int mid = (pa->low + pa->high)/2;
ArrayIndex aIndex[N];
pthread_t thread[N];
aIndex[0].low = pa->low;
aIndex[0].high = mid;
aIndex[1].low = mid+1;
aIndex[1].high = pa->high;
if (pa->low >= pa->high) return 0;
int i;
for(i = 0; i < N; i++) pthread_create(&thread[i], NULL, mergesort, &aIndex[i]);
for(i = 0; i < N; i++) pthread_join(thread[i], NULL);
merge(pa->low, pa->high);
//pthread_exit(NULL);
return 0;
}
int main()
{
ArrayIndex ai;
ai.low = 0;
ai.high = sizeof(a)/sizeof(a[0])-1;
pthread_t thread;
pthread_create(&thread, NULL, mergesort, &ai);
pthread_join(thread, NULL);
int i;
for (i = 0; i < 10; i++) printf ("%d ", a[i]);
cout << endl;
return 0;
}
Possible Duplicate:
No such file iostream.h when including
Even after naming the source file with .cpp extension. my compiler gives this error, both in command prompt and Codeblocks. How can I fix this issue?
#include <iostream.h>
int main(){
cout<<"Hello World!n";
return 0;
}
asked Oct 24, 2012 at 13:12
1
That header doesn’t exist in standard C++. It was part of some pre-1990s compilers, but it is certainly not part of C++.
Use #include <iostream>
instead. And all the library classes are in the std::
namespace, for example std::cout
.
Also, throw away any book or notes that mention the thing you said.
Puppy
144k37 gold badges255 silver badges463 bronze badges
answered Oct 24, 2012 at 13:14
Kerrek SBKerrek SB
462k92 gold badges873 silver badges1080 bronze badges
3
Using standard C++ calling (note that you should use namespace std for cout or add using namespace std;)
#include <iostream>
int main()
{
std::cout<<"Hello World!n";
return 0;
}
paxdiablo
850k233 gold badges1570 silver badges1944 bronze badges
answered Oct 24, 2012 at 13:14
il_guruil_guru
8,3632 gold badges42 silver badges51 bronze badges
1
You should be using iostream
without the .h
.
Early implementations used the .h
variants but the standard mandates the more modern style.
answered Oct 24, 2012 at 13:14
paxdiablopaxdiablo
850k233 gold badges1570 silver badges1944 bronze badges
You should change iostream.h
to iostream
. I was also getting the same error as you are getting, but when I changed iostream.h
to just iostream
, it worked properly. Maybe it would work for you as well.
In other words, change the line that says:
#include <iostream.h>
Make it say this instead:
#include <iostream>
The C++ standard library header files, as defined in the standard, do not have .h
extensions.
As mentioned Riccardo Murri’s answer, you will also need to call cout
by its fully qualified name std::cout
, or have one of these two lines (preferably below your #include
directives but above your other code):
using namespace std;
using std::cout;
The second way is considered preferable, especially for serious programming projects, since it only affects std::cout
, rather than bringing in all the names in the std
namespace (some of which might potentially interfere with names used in your program).
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
1 |
|
01.03.2012, 02:39. Показов 19828. Ответов 19
Доброе время суток.
0 |
Почетный модератор 7390 / 2636 / 281 Регистрация: 29.07.2006 Сообщений: 13,696 |
|
01.03.2012, 02:44 |
2 |
AntiDriver, а в путях инклуда, в которых компилер ищет, есть вообще такая либа? Командой g++ компилишь? Добавлено через 1 минуту
Но при попытке откомпилировать программу на си со сточкой #include <iostream.h> постой, нафига тебе на си иострим? Это плюсы. Руками компилируй, хватит среды насиловать.
0 |
бжни 2473 / 1684 / 135 Регистрация: 14.05.2009 Сообщений: 7,162 |
|
01.03.2012, 03:13 |
3 |
в си нету, не было и не будет iostream
0 |
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
01.03.2012, 13:39 [ТС] |
4 |
Я же уже говорил, что знаю только паскаль, в си по нулям, скачал несколько книжек, там приводятся примеры кода с этим iostream
0 |
Почетный модератор 7390 / 2636 / 281 Регистрация: 29.07.2006 Сообщений: 13,696 |
|
01.03.2012, 13:47 |
5 |
в си по нулям, скачал несколько книжек, там приводятся примеры кода с этим iostream Тебе уже сказали, что это не си, а плюсы.
0 |
fasked 5038 / 2617 / 241 Регистрация: 07.10.2009 Сообщений: 4,310 Записей в блоге: 1 |
||||
01.03.2012, 16:03 |
6 |
|||
#include <iostream.h> и даже если на C++, то все равно неправильно.
0 |
21265 / 8281 / 637 Регистрация: 30.03.2009 Сообщений: 22,646 Записей в блоге: 30 |
|
01.03.2012, 18:26 |
7 |
скачал несколько книжек, там приводятся примеры кода с этим iostream Скорее всего ты невнимательно прочитал название книги, и книга была по Си++, а не по Си. Но если книга была по Си, то смело выбрасывай её в помойку
0 |
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
01.03.2012, 21:34 [ТС] |
8 |
Уже терпение лопается. Все книжки, которые скачиваю, даже по си без плюсов, там этот iostream. Подскажите какую-нибудь где его нет, пожалуйста.
0 |
21265 / 8281 / 637 Регистрация: 30.03.2009 Сообщений: 22,646 Записей в блоге: 30 |
|
01.03.2012, 21:54 |
9 |
0 |
3211 / 1459 / 73 Регистрация: 09.08.2009 Сообщений: 3,441 Записей в блоге: 2 |
|
01.03.2012, 22:35 |
10 |
даже по си без плюсов, там этот iostream можно пример?
0 |
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
01.03.2012, 22:45 [ТС] |
11 |
Удалил уже эту книжку, к сожалению. Хорошо, а как тогда заставить компиляторы с++ в linux видеть этот iostream? Сколько уже сред не ставил, везде одна и та же фигня, не видят. Иначе придётся писать программы под виртуалкой и только для винды. А для собственных нужд как и раньше на паскале.
0 |
21265 / 8281 / 637 Регистрация: 30.03.2009 Сообщений: 22,646 Записей в блоге: 30 |
|
01.03.2012, 23:14 |
12 |
Надо установить компилятор g++ (и его же запускать)
0 |
Почетный модератор 7390 / 2636 / 281 Регистрация: 29.07.2006 Сообщений: 13,696 |
|
02.03.2012, 02:11 |
13 |
Сколько уже сред не ставил, везде одна и та же фигня, не видят А ты не среду ставь, запускай компилятор напрямую и компилируй.
0 |
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
02.03.2012, 23:25 [ТС] |
14 |
Так в том то и дело что g++ (и даже gcc) установлены. Код yegor@t9ttt97t:~/Рабочий стол$ cat 1.cpp #include <iostream.h> void main(); { } yegor@t9ttt97t:~/Рабочий стол$ gcc 1.cpp 1.cpp:1:22: error: iostream.h: Нет такого файла или каталога
0 |
3211 / 1459 / 73 Регистрация: 09.08.2009 Сообщений: 3,441 Записей в блоге: 2 |
|
02.03.2012, 23:41 |
15 |
iostream.h тебе уже говорили, у этого файла нет расширения. только имя. к тому же, две ошибки в одной строке:
void main();
0 |
21265 / 8281 / 637 Регистрация: 30.03.2009 Сообщений: 22,646 Записей в блоге: 30 |
|
03.03.2012, 00:18 |
16 |
Тогда надо установить пакет с названием что-то типа c++devel Добавлено через 14 секунд Добавлено через 4 минуты Добавлено через 1 минуту
0 |
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
03.03.2012, 01:34 [ТС] |
17 |
Эти пакеты уже установлены.
0 |
3211 / 1459 / 73 Регистрация: 09.08.2009 Сообщений: 3,441 Записей в блоге: 2 |
|
03.03.2012, 02:52 |
18 |
ты ошибки в своей мегапрограмме исправил?
0 |
Почетный модератор 7390 / 2636 / 281 Регистрация: 29.07.2006 Сообщений: 13,696 |
|
03.03.2012, 11:40 |
19 |
AntiDriver, $ cat > main.cpp
0 |
0 / 0 / 1 Регистрация: 05.06.2010 Сообщений: 17 |
|
04.03.2012, 17:53 [ТС] |
20 |
Да, исправил всё, всё откомпилировалось. Один пакет из зависимостей почему-то не был установлен. Всем спасибо за ответы!
0 |