0 / 0 / 0 Регистрация: 23.08.2017 Сообщений: 5 |
|
1 |
|
Не могу понять, в чем ошибка26.08.2017, 11:42. Показов 6015. Ответов 10
1 #include <iostream> 6 [Error] ‘end1’ was not declared in this scope Добавлено через 9 минут
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
26.08.2017, 11:42 |
10 |
Заблокирован |
|
26.08.2017, 11:43 |
2 |
endI; ???
0 |
0 / 0 / 0 Регистрация: 23.08.2017 Сообщений: 5 |
|
26.08.2017, 11:47 [ТС] |
3 |
Изначально писала end1 — выдал эту ошибку, на одном форуме вычитала, что надо endI, но ошибка осталась абсолютно такая же.
0 |
16495 / 8988 / 2205 Регистрация: 30.01.2014 Сообщений: 15,611 |
|
26.08.2017, 11:50 |
4 |
Сообщение было отмечено ShaOlin12 как решение Решение
Хочу разобраться с end1, как правильно писать, чтоб не было ошибок с ней Нет никакого
0 |
5 / 5 / 2 Регистрация: 07.04.2016 Сообщений: 88 |
|
26.08.2017, 11:55 |
5 |
нужно писать, например cout<<«My text»<<endl; Добавлено через 1 минуту Добавлено через 56 секунд Добавлено через 1 минуту
0 |
0 / 0 / 0 Регистрация: 23.08.2017 Сообщений: 5 |
|
26.08.2017, 11:56 [ТС] |
6 |
И зачем писать «std» перед cout если заюзали using namespace std??? А вдруг ) заработает)))
0 |
5 / 5 / 2 Регистрация: 07.04.2016 Сообщений: 88 |
|
26.08.2017, 11:57 |
7 |
ShaOlin12 если недавно начали программировать напиши мне в вк, я помогу, ведь я 10 клас и тоже недавно начал, на С++ программирую дето 1.5 года, может 2. Стора в вк https://vk.com/superstrimflusha
0 |
0 / 0 / 0 Регистрация: 23.08.2017 Сообщений: 5 |
|
26.08.2017, 11:57 [ТС] |
8 |
Где endl последняя буква не I, а маленькая l(L)английская л. Все гениальное просто!!!
0 |
5 / 5 / 2 Регистрация: 07.04.2016 Сообщений: 88 |
|
26.08.2017, 11:58 |
9 |
Сообщение было отмечено ShaOlin12 как решение РешениеРад помочь
0 |
0 / 0 / 0 Регистрация: 23.08.2017 Сообщений: 5 |
|
26.08.2017, 12:00 [ТС] |
10 |
Огромное всем спасибо!!!
0 |
5 / 5 / 2 Регистрация: 07.04.2016 Сообщений: 88 |
|
26.08.2017, 12:01 |
11 |
Напишите мне в вк)
0 |
Forum
- Beginners
- Windows Programming
- UNIX/Linux Programming
- General C++ Programming
- Lounge
- Jobs
- Forum
- Beginners
- error: ‘end1’ was not declared in this s
error: ‘end1’ was not declared in this scope
I get the error at line 17
error: 'end1' was not declared in this scope
But there is a n end one here is my code
|
|
you wrote end1 (one) instead of endl (line)
Topic archived. No new replies allowed.
I just started using Eclipse to program C++ and I’m running into issues. I have MinGW installed. Right now I have a simple addition program as followed:
#include <iostream>
using namespace std;
int main() {
int number1;
int number2;
int sum;
cout << "Enter first integer: ";
cin >> number1;
cout << "Enter second integer: ";
cin >> number2;
sum = number1 + number2;
cout << sum << end1;
}
and I have an error Symbol end1 could not be resolved
and end1 was not declared in this scope
I had this error before with using namespace std;
and I had to go through some configurations to get the MinGW compiler to work with Eclipse. I don’t understand why this error is still coming up. On a somewhat side note I tried removing end1
and running the program and the console just said, «Info: Nothing to build for CTest» (which is the name of my Project folder name). Any help would be much appreciated.
EDIT: The «can not be resolved issue has been fixed by changing end1
to endl
but the console is still saying «nothing to build»
- Forum
- Other
- General Programming
- [error]»end» was not declared in this scope
-
26th March 2016, 11:08
#1
[error]»end» was not declared in this scope
I was learning programming from a book, in it there was a program which I have typed out and am recieving an error
[Error] ‘end’ was not declared in this scope
This is the program please tell me what is wrong
#include<iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << endl;
std::cout << x + y <<«»<< x * y;
std::cout <<end;
return 0;}
error1.jpg
-
26th March 2016, 12:26
#2
Re: [error]»end» was not declared in this scope
Your «end» is an «endl» with the «l» missing.
Cheers,
_
-
26th March 2016, 20:20
#3
Re: [error]»end» was not declared in this scope
Hello,
don’t forget the namespace std. Change lines 6 and 8 to
std::cout << std::endl;
To copy to clipboard, switch view to plain text mode
Note: add the missing ‘l’ to end in line 8 (as anda_skoa already pointed out).
Best regards
ars
Similar Threads
-
Replies: 1
Last Post: 2nd June 2015, 21:02
-
Replies: 3
Last Post: 28th January 2013, 00:53
-
Replies: 2
Last Post: 28th February 2010, 08:38
-
Replies: 1
Last Post: 5th June 2008, 12:45
-
Replies: 3
Last Post: 23rd May 2007, 16:58
Bookmarks
Bookmarks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
- BB code is On
- Smilies are On
- [IMG] code is On
- [VIDEO] code is On
- HTML code is Off
Forum Rules
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.
-
#1
I have just started learning C++ from the book «SAMS Teach Yourself C++ in 21 Days» and the very first exercise (after Hello World) won’t compile in g++. I’ve checked to make sure I wasn’t making any typos or anything, and I have definitely typed exactly what it says in the book.
Here is the code:
#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << end1;
std::cout << x + y << » » << x * y;
std::cout << end;
return 0;
}
and the errors are as follows:
Untitled.cpp: In function `int main()’:
Untitled.cpp:6: error: ‘end1’ was not declared in this scope
Untitled.cpp:8: error: ‘end’ was not declared in this scope
Does it have something to do with the compiler, or maybe with my system (Mac OS X 10.4.11 running on a 800 MHz PowerPC G4 iMac)?
I saw this same question by a Linux user somewhere else on the internet, and it seems that the consensus there is that the book has made an error. Though this is possible, I have heard many good things about this book from multiple sources, and I kind of doubt that this is the case.
Anyway, I hope somebody can help me and reply soon.
Thanks in advance,
Alex.
-
#2
change end1 to endl (the last character is a lowercase L). It might need to be std::endl or add using namespace std;
-Lee
-
#3
end1 needs to be endl
it’s «L» not «1»
and std::cout is correct but, if you use namespace std then you do not have to type std:: all the time
-
#4
Thank you so much. I fixed what you told me was wrong and now I have:
#include <iostream>
int main()
{
int x = 5;
int y = 7;
std::cout << std::endl;
std::cout << x + y << » » << x * y;
std::cout << std::end;
return 0;
}
but I still have errors:
Untitled.cpp: In function `int main()’:
Untitled.cpp:8: error: ‘end’ is not a member of ‘std’
Is «end» supposed to «endl» too? That seems logical, and it compiles, but why are two of the same line necessary?
Because I’ve hardly even gotten into this book, I am not sure how to use «namespace std;» but I don’t know if that would actually fix anything, if it’s just an alternative (of course I know nothing).
Thank you so much,
Alex.
-
#5
change the end to another std::endl on line 8.
-
#6
Thank you so much. I fixed what you told me was wrong and now I have:
but I still have errors:
Is «end» supposed to «endl» too? That seems logical, and it compiles, but why are two of the same line necessary?
Because I’ve hardly even gotten into this book, I am not sure how to use «namespace std;» but I don’t know if that would actually fix anything, if it’s just an alternative (of course I know nothing).
Thank you so much,
Alex.
That line just prints an empty line. They used it twice to print two empty lines. The reason it is necessary is because whoever wrote the code wanted it there. lol no other reason
And yes it needs to be «endl» and not «end».
-
#7
Okay, everything is working. Thanks a lot to everyone who replied.
Alex.
-
#8
Just a note to find any more errors that crop up, the number 8 in this line
Untitled.cpp:8: error: ‘end’ was not declared in this scope
is a good starting point on where to look first for the error, ie in line 8
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <sys/socket.h>
#include <sys/unistd.h>
#include <sys/types.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <signal.h>
#include <iostream>
#include <thread>
using namespace std;
#define BUFFSIZE 2048
#define DEFAULT_PORT 4001 //
#define MAXLINK 2048
void connecter()
{
printf("Listening...n");
while (true)
{
signal(SIGINT, stopServerRunning); //
//
connfd = accept(sockfd, NULL, NULL);
if (-1 == connfd)
{
printf("Accept error(%d): %sn", errno, strerror(errno));
return -1;
}
}
}
void listener()
{
while(true)
{
bzero(buff, BUFFSIZE);
//
recv(connfd, buff, BUFFSIZE - 1, 0);
//
printf("клиент: %sn", buff);
//
send(connfd, buff, strlen(buff), 0);
}
}
void sender()
{
while(true)
{
printf("Please input: ");
scanf("%s", buff);
send(connfd, buff, strlen(buff), 0);
bzero(buff, sizeof(buff));
recv(connfd, buff, BUFFSIZE - 1, 0);
printf("recv: %sn", buff);
}
}
int sockfd, connfd;
void stopServerRunning(int p)
{
close(sockfd);
printf("Close Servern");
exit(0);
}
int main()
{
struct sockaddr_in servaddr;
char buff[BUFFSIZE];
//
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (-1 == sockfd)
{
printf("Create socket error(%d): %sn", errno, strerror(errno));
return -1;
}
//
//
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(DEFAULT_PORT);
if (-1 == bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr)))
{
printf("Bind error(%d): %sn", errno, strerror(errno));
return -1;
}
//
//
if (-1 == listen(sockfd, MAXLINK))
{
printf("Listen error(%d): %sn", errno, strerror(errno));
return -1;
}
while(true)
{
thread my_thread(connecter);
if(connfd == true)
break;
}
thread my_thread(connecter);
thread my_thread(listener);
thread my_thread(sender);
return 0;
}
}
это исходный код программы, хотел написать что-то вроде чата на сокетах. Я попытался скомпилировать код, но он мне выдал несколько ошибок «was not declared in this scope». Вот вывод компилятора:
server.cpp: In function ‘void connecter()’:
server.cpp:24:24: error: ‘stopServerRunning’ was not declared in this scope
24 | signal(SIGINT, stopServerRunning); // Это предложение используется для выключения сервера при вводе Ctrl + C
|
server.cpp:26:9: error: ‘connfd’ was not declared in this scope
26 | connfd = accept(sockfd, NULL, NULL);
| ^~~~~~
server.cpp:26:25: error: ‘sockfd’ was not declared in this scope; did you mean ‘socket’?
26 | connfd = accept(sockfd, NULL, NULL);
| ^~~~~~
| socket
server.cpp: In function ‘void listener()’:
server.cpp:39:15: error: ‘buff’ was not declared in this scope
39 | bzero(buff, BUFFSIZE);
| ^~~~
server.cpp:41:14: error: ‘connfd’ was not declared in this scope
41 | recv(connfd, buff, BUFFSIZE - 1, 0);
| ^~~~~~
server.cpp: In function ‘void sender()’:
server.cpp:54:21: error: ‘buff’ was not declared in this scope
54 | scanf("%s", buff);
| ^~~~
server.cpp:55:14: error: ‘connfd’ was not declared in this scope
55 | send(connfd, buff, strlen(buff), 0);
| ^~~~~~
я думаю, что все эти ошибки идут из одной проблемы, но не могу понять откуда
Table of Contents
Common G++ Errors
Summary
This is a guide to help you CS35ers make sense of g++ and its often cryptic error messages.
If you discover an error not listed here feel free to edit this wiki,
or send your error along with source code and an explanation to me — grawson1@swarthmore.edu
Weird Errors
If you are getting strange compiler errors when your syntax looks fine, it might be a good idea to check that your Makefile is up to date
and that you are including the proper .h files. Sometimes a missing } or ; or ) will yield some scary errors as well.
Lastly, save all files that you might have changed before compiling.
Bad Code Sample
What’s wrong with the following code? (Hint: there are two errors)
#include<iostream> using namespace std; int main(){ int foo; for(int i = 0, i<100, i++) { foo++; cout << foo << endl; } return 0; }
When compiled this yields:
junk.cpp:9: error: expected initializer before '<' token
junk.cpp:13: error: expected primary-expression before 'return
‘
junk.cpp:13: error: expected `;' before 'return
‘
junk.cpp:13: error: expected primary-expression before 'return
‘
junk.cpp:13: error: expected `)' before 'return
‘
First, the parameters of the for
loop need to be separated by semicolons, not commas.
for(int i = 0; i<100; i++) { foo++; cout << foo << endl; }
Now look at this sample output of the corrected code:
-1208637327
-1208637326
-1208637325
-1208637324
-1208637323
-1208637322
Why the weird values? Because we never initialized foo
before incrementing it.
int foo = 0;
‘cout’ was not declared in this scope
Two things to check here:
(1) Did you add
#include<iostream>
to your list of headers?
(2) Did you add
using namespace std;
after your #includes?
‘printf’ was not declared in this scope
Add
#include<cstdio>
to your list of headers. Note if you are coming from C programming, adding
#include<cstdio> is preferred in C++ over #include <stdio.h>.
Cannot Pass Objects of non-POD Type
junk.cpp:8: warning: cannot pass objects of non-POD type 'struct std::string' through '…'; call will abort at runtime
junk.cpp:8: warning: format '%s' expects type 'char*', but argument 2 has type 'int
‘
What this usually means is that you forgot to append .c_str() to the name of your string variable when using printf.
This error occurred when trying to compile the following code:
int main(){ string foo = "dog"; printf("This animal is a %s.n",foo); return 0; }
Simply appending to .c_str() to “foo” will fix this:
printf("This animal is a %s.n",foo.c_str());
The reason you got this error is because printf is a C function and C handles strings differently than C++
Invalid Use of Member
junk.cpp:8: error: invalid use of member (did you forget the '&' ?)
What this usually means is that you forget to add () to the end of a function call.
Ironically, every time I see this it is never because I forgot the ‘&’.
This error occurred when trying to compile the following code:
int main(){ string foo = "dog"; printf("This animal is a %s.n",foo.c_str); return 0; }
Simply adding the open and close parentheses () will take care of this for you:
printf("This animal is a %s.n",foo.c_str());
Request for Member ‘Foo’ in ‘Bar’, which is of non-class type ‘X’
trycredit.cpp:86: error: request for member 'print' in 'card', which is of non-class type 'CreditCard*
‘
What this usually means is that you are using a ‘.’ between the class pointer and the function you are trying to call.
Here is an example from the CreditCard lab:
void useCard(CreditCard *card, int method) { //Used to access the methods of the class if (method==1) { card.print(); }
Since card
is a CreditCard* we need → rather than . Fixed:
if (method==1) { card->print(); }
Undefined Reference to V Table
This error usually means you need to add a destructor to your myClass.cpp/myClass.inl code.
If you don’t want to implement a real destructor at this point, you can write something like this:
myClass::~myClass(){}
So long as the destructor exists, you should now be able to compile fine. Of course,
implement a real destructor at a later point.