Error system was not declared in this scope

Не компилируется приложение: 'system' was not declared in this scope C++ Решение и ответ на вопрос 1257241

mak17

3 / 3 / 2

Регистрация: 09.09.2014

Сообщений: 38

1

16.09.2014, 17:50. Показов 18473. Ответов 7

Метки нет (Все метки)


Привет всем, теперь на форуме на одного глупого первокурсника больше)
Немогу откомпилировать, хотя в универе тотже код работает нормально.
Ошибки:

Кликните здесь для просмотра всего текста

C:UsersMarkDesktopProgrammingst140167Program mingformula2.cpp In function ‘int main()’::
19 C:UsersMarkDesktopProgrammingst140167Program mingformula2.cpp:16 ‘system’ was not declared in this scope

Софт — Win7x64, wxDev-C++

C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{//float x,y,z
double y,x,z,a,b;
{
   cout<<"ievadi a(int) = ";
   cin>>a;
   cout<<"ievadi b(int) = ";
   cin>>b;
}
z=(a+5)*(b-1)/(a*2+1);
cout<<"n z = "<<z;
 
system("pause>nul");
return 0;
}

__________________
Помощь в написании контрольных, курсовых и дипломных работ, диссертаций здесь



0



ranebull

545 / 378 / 56

Регистрация: 23.06.2013

Сообщений: 1,181

Записей в блоге: 6

16.09.2014, 17:55

2

Цитата
Сообщение от mak17
Посмотреть сообщение

#include <iostream>
#include <cmath>

Добавьте

C++
1
#include<cstdlib>



0



mak17

3 / 3 / 2

Регистрация: 09.09.2014

Сообщений: 38

16.09.2014, 18:06

 [ТС]

3

Заработало!
А можете сказать почему на компе универа это работало без

C++
1
#include<cstdlib>

?



0



:)

Эксперт С++

4773 / 3267 / 497

Регистрация: 19.02.2013

Сообщений: 9,046

16.09.2014, 18:32

4

Цитата
Сообщение от mak17
Посмотреть сообщение

почему на компе универа это работало без

потому, что кто какой хедер косвенно подключает не регламентировано Стандартом. Разные компиляторы по-разному себя ведут в этом плане. Чтобы от этого не зависеть, следует явно подключать те хедеры, в которых объявлены используемые функции.



0



5493 / 4888 / 831

Регистрация: 04.06.2011

Сообщений: 13,587

17.09.2014, 02:31

5

Цитата
Сообщение от mak17
Посмотреть сообщение

А можете сказать почему на компе универа это работало без

Скорее всего, там компилятор не mingw.



0



Форумчанин

Эксперт CЭксперт С++

8193 / 5043 / 1437

Регистрация: 29.11.2010

Сообщений: 13,453

17.09.2014, 11:57

6

Цитата
Сообщение от alsav22
Посмотреть сообщение

Скорее всего, там компилятор не mingw.

Я встречал сборки mingw, которые также неявно подключали cstdlib. Хотя вы скорее всего правы..

В дополнении к исчерпывающему ответу Tulosba, советую при сомнениях проверять в каком заголовочном файле находится тот или иной класс/функция/переменная с помощью сервисов
http://en.cppreference.com/w/c… ram/system
http://www.cplusplus.com/refer… ?kw=system



0



Electra2005

1 / 1 / 0

Регистрация: 10.01.2011

Сообщений: 82

18.06.2022, 13:09

7

А почему ругается на

C++
1
using System;

[Error] ‘System’ has not been declared



0



2057 / 1615 / 532

Регистрация: 29.06.2020

Сообщений: 6,082

18.06.2022, 14:04

8

Цитата
Сообщение от Electra2005
Посмотреть сообщение

using System;

Это с другой оперы.



0



#include<iostream>
#include<conio.h>
#include<cmath>
using namespace std;
int main ()
{
char choice, choice1, choice2, choice3, choice4;
int x,y;
double x1,y1;
int answer;
double answer1;
double angle;
cout<<» Welcome to TwoSixEight Geeka Scientific Calculator : «;
cout << » Coded by Jenell Joanne James»;
do

{

cout<<«t1 : Arithmetic Operations n: «;
cout<<«t2 : Trigonometric Functions n: «;
cout<<«t3 : Logarithmic Functions n: «;
cout<<«t4 : Power Functions n: «;
choice = getche();

switch(choice)

{
case ‘1’:

{

cout<<«t1 : Addition n: «;
cout<<«t2 : Subtraction n: «;
cout<<«t3 : Multipilication n: «;
cout<<«t4 : Division n: «;
choice1 = getche();
switch(choice1)
{
case ‘1’:
{
cout<<«Enter first number: » ;
cin>>x;
cout<<» Enter second number: «;
cin>>y;
answer= x+y;
cout<<«answer «<<answer <<endl;
system(«pause»);
break;
}
case ‘2’:
{
cout<<«Enter first number: «;
cin>>x;
cout<<«Enter an other number: «;
cin>>y;
answer=x-y;
cout<<«answer is «<<answer<<endl;
system(«pause»);
break;
}

case ‘3’:
{
cout<<«Enter first number: «;
cin>>x;
cout<<«Enter an other number: «;
cin>>y;
answer=x*y;
cout<<» answer is» <<answer <<endl;
system(«pause»);
break;
}

case ‘4’:
{
cout<<«Enter first number: «;
cin>>x;
cout<<«Enter an other number: «;
cin>>y;
if(x!=0)
{
answer=x/y;
cout<<«answer «<<answer<<endl;
system(«pause»);
}
break;
}

}// end of inner switch
break;
}// end of case 1 arithmatic operation

case ‘2’:
{

cout<<«t1 : Sin function n: «;
cout<<«t2 : Cos function n: «;
cout<<«t3 : Tan function n: «;
choice2=getche();
switch(choice2)
{
case ‘1’:
{
cout<<«Enter a angle: «;
cin>>angle;

answer1=(sin(angle));
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;
}
case ‘2’:
{
cout<<» Enter a number: «;
cin>>angle;
answer1=(cos(angle));
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;
}
case ‘3’:
{
cout<< «Enter a number: «;
cin>>angle;
answer1=(tan(angle));
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;

}

}// inner switch
break;
}//inner case 2 trignomatic
case ‘3’:
{

cout<<«t1 : Natural log n: «;
cout<<«t2 : log with base 10 n: «;
choice3=getche();
switch(choice3)
{
case ‘1’:
{
cout<<» Enter a number: «;
cin>>x1;
answer1=log(x1);
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;
}
case ‘2’:
{
cout<<«Enter a number: «;
cin>>x1;
answer1= log10(x1);
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;
}
}// end of switch
break;
}// end of case 3 logrithmic
case ‘4’:
{
system(«cls»);
cout<<«t1 : Press 1 for Power: «;
cout<<«t2 : Press 2 for Square root: «;
cout<<«t3 : Press 3 for square: «;
cout<<«t4 : Press 4 for cude: «;
cout<<«Enter your choice: «;
choice4=getche();
switch(choice4)
{
case ‘1’:
{
cout<<«Enter a number: «;
cin>>x1;
cout<<«Enter power: «;
cin>>y1;
answer1=pow(x1,y1);
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;
}
case ‘2’:
{
cout<<«Enter a number: «;
cin>>x;
answer1=sqrt(x);
cout<<«answer is «<<answer1<<endl;
system(«pause»);
break;

}
case ‘3’:
{
cout<<» Enter a number: «;
cin>>x;
answer1= x*x;
cout<<» answer is»<<answer1<<endl;
system(«pause»);
break;

}
case ‘4’:
{
cout<<» Enter a number: «;
cin>>x;
answer1 =x*x*x;
cout<<» answer is»<<answer1<<endl;
system(«pause»);
break;
}

}// end of switch
break;
}// end of case power function

}// outer switch
}while(choice!= ‘5’);

return 0;
}

Where do you declare

system

… or #include the header that does so?

#include <cstdlib>

thank lechuga2000 i got it….

Try not to use system() functions for any stop you want in the program. It’s like using a sledgehammer to kill a fly. It’d better be a damn big fly to do so.

In other words, it uses too much resources for the little task you need it for. Imagine hypothetically, where you’re running some super heavy programs (Witcher 3, Crysis 2, Photoshop, Chrome, a benchmark tester) in the background and programming/doing your hw at the same time. The amount of computing power a system("pause") needs compared to a simple cin.ignore( 999, 'n' ) would be the difference in a crash or not.

Now imagine that in the real world, with a job. You’d get fired.

Come on, code tags — we have talked about this already ……

Topic: CodeBlocks 10.05 — ‘system’ was not declared in this scope  (Read 33828 times)

rantic

Hi everyone,

I have been teaching myself to program in C++ for a few months now using Code::Blocks 8.02 and decided to upgrade to 10.05 today when I saw it on the website.

I uninstalled 8.02 in add/remove programs before installing 10.05. Unfortunately after launching 10.05 for the first time (without a hitch) I opened up a few of my old C++ projects to fiddle with and noticed they no longer compile.

Here are my compile errors for basically every program.

C:UsersmetaDocumentsMy Dropboxschoolsemester 2comp1200 - c++Assignmentsassignment_1assignment_1.cpp||In function 'int main()':|
C:UsersmetaDocumentsMy Dropboxschoolsemester 2comp1200 - c++Assignmentsassignment_1assignment_1.cpp|63|error: 'system' was not declared in this scope|
C:UsersmetaDocumentsMy Dropboxschoolsemester 2comp1200 - c++Assignmentsassignment_1assignment_1.cpp||In function 'void printResults(std::string, int, int, double, double)':|
C:UsersmetaDocumentsMy Dropboxschoolsemester 2comp1200 - c++Assignmentsassignment_1assignment_1.cpp|135|error: 'system' was not declared in this scope|
C:UsersmetaDocumentsMy Dropboxschoolsemester 2comp1200 - c++Assignmentsassignment_1assignment_1.cpp|136|error: 'exit' was not declared in this scope|
||=== Build finished: 3 errors, 0 warnings ===|

I tried to google this and some said it might be using the Microsoft Visual C++ Compiler, but from what I can tell looking in the options it isn’t. I also searched this forum and found a post (link below) but it didn’t really provide any helpful information on how to get this fixed. Any information would be gladly appreciated!

http://forums.codeblocks.org/index.php/topic,12513.0.html

Code::Blocks Version: 10.05
Operating System: Windows 7 — 64bit

« Last Edit: June 03, 2010, 01:07:34 am by rantic »


Logged


Here are my compile errors for basically every program.

This means that some #include file where those symbols were defined/declared is not being included. Make sure that you have all the directories specified in the «search directories» tab, in the section related to the compiler.

Ken


Logged



Logged

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.

When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org


Have you included

<cstdlib>

? Both

exit

and

system

are defined there, and seeing as you’re getting no other errors (e.g. related to

cout

) that omission could well be the problem.


Logged


 Seoaction.net - seo и не только...

Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.

 

Новости:

Если Вы не можете войти на форум, потому что не подходит пароль, его нужно восстановить по указанной там ссылке.
http://seoaction.net/index.php?topic=877

  • Начало

  • Поиск

  • Календарь

  • Вход

  • Регистрация

  • Seoaction.net — seo и не только… »
  • Веб-строительство и веб-дизайн »
  • Программирование »
  • C, C++, C# (Си, Си плюс, Си флеш) »
  • error: ‘system’ was not declared in this scope

« предыдущая тема следующая тема »

  • Ответ
  • Печать

Страницы: [1]   Вниз


Автор
Тема: error: ‘system’ was not declared in this scope  (Прочитано 794 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Mukhlis

  • Гость

error: ‘system’ was not declared in this scope

« : 03 Июнь 2016, 23:14:26 »

  • Цитировать

Отцы, только учусь!
В первой же программа — ошибка!
14|error: ‘system’ was not declared in this scope
14 строка — вот! system(«pause»);

Как убрать эту ошибку!


so1o

  • Гость

error: ‘system’ was not declared in this scope

« Ответ #1 : 07 Июнь 2016, 12:53:03 »

  • Цитировать

Подключите заголовочный файл
#include<cstdlib>


  • Ответ
  • Печать

Страницы: [1]   Вверх

« предыдущая тема следующая тема »

  • Seoaction.net — seo и не только… »
  • Веб-строительство и веб-дизайн »
  • Программирование »
  • C, C++, C# (Си, Си плюс, Си флеш) »
  • error: ‘system’ was not declared in this scope


+

Быстрый ответ

В быстром ответе можно использовать BB-теги и смайлы.

Имя:
E-mail:

Ошибка во время нажатия Спасибо

Спасибо…

  • SMF 2.0.9 |
    SMF 2013
  • XHTML
  • RSS
  • Sitemap XML
  • Мобильная версия

Размер занимаемой памяти: 2 мегабайта.
Страница сгенерирована за 0.072 секунд. Запросов: 34.

Понравилась статья? Поделить с друзьями:
  • Error system service exception
  • Error system reflection targetinvocationexception рыбалка
  • Error system reflection targetinvocationexception как исправить
  • Error system reflection targetinvocationexception адресат вызова создал исключение
  • Error system reflection targetinvocationexception playlist finder