- VsCode Version: 1.23.1
- Extension Version: 0.17.1
- Os: Win10 Pro Education
- Version: 1803
- gcc : wsl ubuntu16.04(5.4)
I’ve followed instruction described in https://github.com/Microsoft/vscode-cpptools/blob/master/Documentation/LanguageServer/Windows%20Subsystem%20for%20Linux.md, however, the intellisense tool generate: namespace «std» has no member «cout». This issue also is presented with other members in headers I use in my project, e.g., namespace «omnetpp» has no member «simsignal_t»
c_cpp_properties.json
{
"configurations": [
{
"name": "WSL",
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"includePath": [
"${workspaceFolder}",
"/mnt/c/Users/Geo/omnetpp-5.2/include",
"/mnt/c/Users/Geo/omnetpp-5.2/include/omnetpp",
"/mnt/c/Users/Geo/omnetpp-5.2/include/omnetpp/platdep",
"/mnt/c/Users/Geo/omnetpp-5.2/include/platdep",
"/mnt/c/Users/Geo/omnetpp-5.2/src/cmdenv",
"/mnt/c/Users/Geo/omnetpp-5.2/src/common",
"/mnt/c/Users/Geo/omnetpp-5.2/src/envir",
"/mnt/c/Users/Geo/omnetpp-5.2/src/eventlog",
"/mnt/c/Users/Geo/omnetpp-5.2/src/layout",
"/mnt/c/Users/Geo/omnetpp-5.2/src/nedxml",
"/mnt/c/Users/Geo/omnetpp-5.2/src/qtenv",
"/mnt/c/Users/Geo/omnetpp-5.2/src/qtenv/osg",
"/mnt/c/Users/Geo/omnetpp-5.2/src/scave",
"/mnt/c/Users/Geo/omnetpp-5.2/src/sim",
"/mnt/c/Users/Geo/omnetpp-5.2/src/sim/netbuilder",
"/mnt/c/Users/Geo/omnetpp-5.2/src/sim/parsim",
"/mnt/c/Users/Geo/omnetpp-5.2/src/tkenv",
"/mnt/c/Users/Geo/inet/src",
"/mnt/c/Users/Geo/inet/src/inet",
"/mnt/c/Users/Geo/inet/src/inet/common",
"/mnt/c/Users/Geo/inet/src/inet/common/geometry/common",
"/mnt/c/Users/Geo/inet/src/inet/mobility/base",
"/mnt/c/Users/Geo/inet/src/inet/mobility/contract",
"/mnt/c/Users/Geo/inet/src/inet/mobility/single",
"${workspaceRoot}/src",
"${workspaceRoot}/src/base",
"${workspaceRoot}/src/engine",
"${workspaceRoot}/src/simple"
],
"defines": [
],
"browse": {
"path": [
"${workspaceFolder}",
"/mnt/c/Users/Geo/omnetpp-5.2/include",
"/mnt/c/Users/Geo/omnetpp-5.2/src",
"/mnt/c/Users/Geo/inet/src",
"/mnt/c/Users/Geo/gsim/slaw/src"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
- Forum
- Beginners
- error: no type named ‘cout’ in namespace
error: no type named ‘cout’ in namespace ‘std’
I must have introduced some error that I can’t pinpoint
been writing
using std::cout;
instead of using namespace;
but somehow i can’t compile this and I keep getting
error: no type named ‘cout’ in namespace ‘std’
|
|
Last edited on
and if i write the code as follows, there’s no compilation error.
i’m trying to figure out what I did wrongly with the code in the first post.
|
|
In the OP, L26 & L29-31 are not within the function definition. Hence errors.
thanks seeplus, now I see my mistake.
much appreciated.
Hi,
It might seem easier to put using std::cout; et al at the beginning of your files, there will come a point when you get tired of having lots of these in a file. It is annoying if you give part of your code to others, they discover it doesn’t compile because the offending using statements aren’t there. Then one has to go through and fix these issues. It is better to do the following and not create issues.
It’s probably better to just put std:: before each std thing. One gets used to it; it should also possible to setup keyboard shortcuts in your IDE. I gather these are the things that coding professionals do.
Edit
IIt should also be possible to setup the IDE editor to automatically do pairs of braces, parentheses etc. , so no more having code outside functions, classes etc.
Last edited on
There is a more efficient way to print duplicated numbers using a std::map:
|
|
Output:
1 2 5 ** Running time: 755 micros 1 2 5 ** Running time: 298 micros Press any key to close this window . . .
Last edited on
Well on my system I get (as x64):
1 2 5 ** Running time: 464 micros 1 2 5 ** Running time: 938 micros
…..
Very strange. I tried x64 on VS 2019 Release and the first version is even worse:
1 2 5 ** Running time: 1449 micros 1 2 5 ** Running time: 322 micros
Maybe later I have more time and can try https://quick-bench.com
Last edited on
I agree that from the code the second should be faster. Tried again:
1 2 5 ** Running time: 432 micros 1 2 5 ** Running time: 976 micros
maybe it’s something in the timing…
On MinGW with -O3 results are much more extreme:
5 1 2 ** Running time: 985 micros 1 2 5 ** Running time: 18 micros
|
|
On Coliru:
g++ -std=c++20 -O3 -Wall -Wextra -pedantic-errors main.cpp && ./a.out echo ================================ clang++ -std=c++2a -O3 -Wall -Wextra -pedantic-errors main.cpp && ./a.out found 471 duplicate items using std::set : 2701.25 millisecs processor, 2701 millisecs wall clock found 471 duplicate items using std::unordered_set : 1249.6 millisecs processor, 1249 millisecs wall clock ================================ found 469 duplicate items using std::set : 2578.7 millisecs processor, 2578 millisecs wall clock found 469 duplicate items using std::unordered_set : 1223.97 millisecs processor, 1223 millisecs wall clock
http://coliru.stacked-crooked.com/a/9d82db611cf15048
(Note that for unordered set, insertion would be expensive when rehashing is required.)
Topic archived. No new replies allowed.
- Remove From My Forums
-
Question
-
#include<iostream>
#include «stdafx.h»
#include<string>
using namespace std;
#include<io.h>void search(string path,int layer)
// path stands for the folder name; layer stands for the current level of file systems
{
struct _finddata_t filefind;
string curr = path+»\*.*»;
int done = 0, i, handle;if((handle=_findfirst(curr.c_str(),&filefind))==-1){
return; // no file exist in the folder
}while(!(done=_findnext(handle,&filefind)))
{
if(!strcmp(filefind.name,»..»))
continue;for(i=0;i<layer;i++) cout<<» «;
if ((_A_SUBDIR==filefind.attrib)) // if it is a fodler
{
std::cout<<filefind.name<<«(dir)»<<endl;
curr=path+»\»+filefind.name;
search(curr,layer+1);
}
else
{
cout<<filefind.name<<endl;
}
}
_findclose(handle);
}
void main()
{
string path;
cout<<«input folder name»<<endl;
cin>>path;
search(path,0);
}
// that’s the source code>—— Build started: Project: Gary2, Configuration: Debug Win32 ——
1>Compiling…
1>directory.cpp
1>c:usersgarydocumentsvisual studio 2005projectsgary2gary2directory.cpp(17) : warning C4244: ‘=’ : conversion from ‘intptr_t’ to ‘int’, possible loss of data
1>c:usersgarydocumentsvisual studio 2005projectsgary2gary2directory.cpp(26) : error C2065: ‘cout’ : undeclared identifier
1>c:usersgarydocumentsvisual studio 2005projectsgary2gary2directory.cpp(30) : error C2039: ‘cout’ : is not a member of ‘std’
1>c:usersgarydocumentsvisual studio 2005projectsgary2gary2directory.cpp(45) : error C2065: ‘cin’ : undeclared identifier
Answers
-
Thank you, I have already found the solution. The fatal error i made here is putting stdfax in the wrong position. I should put it in the front of iostream
-
Marked as answer by
Thursday, December 17, 2009 7:13 AM
-
Marked as answer by
|
Dimedron 0 / 0 / 0 Регистрация: 09.09.2015 Сообщений: 1 |
||||
|
1 |
||||
|
06.06.2017, 21:00. Показов 34078. Ответов 1 Метки нет (Все метки)
Вот такие ошибки в общем Собственно, вот сам код
__________________
0 |
|
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
06.06.2017, 21:00 |
|
Ответы с готовыми решениями: error C2886: std::cout: использование символа в «using»-объявлении члена не допускается
В зависимости от времени года «весна», «лето», «осень», «зима» определить погоду «тепло», «жарко», «холодно», «очень холодно» namespace «std» has no member «vector» 1 |
|
test local function definitions are illegal C++ |
|
|
Error C2660 : function does not take 3 arguments |
|
|
Error LNK2019 unresolved external symbol |
|
|
E0042 operand types are incompatible ( char and const char * ) |
|
|
E0025 quoted string should contain at least one character |
|
|
error: ‘cout’ in namespace ‘std’ does not name a type |
|
|
undefined reference to `std::cout’ |
Если начинается на C, то это ошибка компиллятора.
Если на L, то линкера.
test local function definitions are illegal C++
Появляется если Вы случайно определили функцию не перед main а внутри main.
Error C2660 : function does not take 3 arguments
Компилятор ждёт, что у функции будет другое количество аргументов.
Появляется, например, если Вы не подключили нужную функцию, но существует
функция перегрузка с другим количеством аргументов. Копилятор не находит
нужную функцию, находит ту у которой такое же название, пытается использовать,
но количество аргументов неправильно.
Error LNK2019 unresolved external symbol
Линкер видит, что вызывается функция, которая нигде не задана.
E0042 operand types are incompatible ( char and const char * )
Появляется обычно при сравнении char с символом в двойных кавычках.
Нужно заменить двойные кавычки одинарными
char s = line[0];
if (s == 'T') {
std::cout << "TopBicycle.ru" << std::endl;
}
E0025 quoted string should contain at least one character
Обычно появляется когда вы пытаетесь создать пустую строку но делаете это с одинарными кавычками.
Нужно заменить одинарные кавычки двойными.
empty_line = "";
‘cout’ in namespace ‘std’ does not name a type
error: ‘cout’ in namespace ‘std’ does not name a type
Скорее всего вы пытаетесь сделать вывод без функции
std::cout << «Hello»;
С++ на это ругается, поэтому нужно завернуть вывод в функцию
void log() {
std::cout << «Hello»;
}
undefined reference to `std::cout’
undefined reference to `std::cout’
Означает, что скорее всего вам нужен g++ а не gcc

Где ошибка невозможно преобразовать указатель «this» из «const pers» в «pers &» при выводе объектов через cout