Jacky
what’s the matter?
Shubh
skip the second student name
Jacky
….., because it has too much newline character, u need to use the getchar() or other func to resolve
Jacky
u can see it in c primer plus, btw
Shubh
ok
...
class A { public: A() { try { b = new B(); } catch (std::bad_alloc) { cerr << "Couldn't create b.\n"; } }; ~A(); }; class B { public: B() { try { c = new C(); throw(bad_alloc()); } catch (std::bad_alloc) { cerr << "Couldn't create c.\n"; throw(std::bad_alloc()); } }; ~B(); C *c; }; int main() { A *a = new A(); return 0; };
<stdin>:5:17: error: use of undeclared identifier 'b' b = new B(); ^ <stdin>:5:25: error: unknown type name 'B' b = new B(); ^ <stdin>:6:22: error: use of undeclared identifier 'std' } catch (std::bad_alloc) { ^ <stdin>:7:17: error: use of undeclared identifier 'cerr' cerr << "Couldn't create b.\n"; ^ <stdin>:25:9: error: unknown type name 'C' C *c; ^ <stdin>:17:25: error: unknown type name 'C' c = new C(); ^ <stdin>:18:23: error: use of undeclared identifier 'bad_alloc' throw(bad_alloc()); ^ <stdin>:19:22: error: use of undeclared identifier 'std' } catch (std::bad_alloc) { ^ <stdin>:20:17: error: use of undeclared identifier 'cerr' cerr << "Couldn't create c.\n"; ^ <stdin>:21:23: error: use of undeclared identifier 'std' throw(std::bad_alloc()); ^ <stdin>:29:8: warning: unused variable 'a' [-Wunused-variable] A *a = new A(); ^ 1 warning and 10 errors generated.
Spirit
I think his message was pseudocode
Yeah basically. It seemed unimportant to add all the included and using statements. I think there was plenty of info to understand what was going on. And It was just an example of what I was trying to understand.
Set41
Hello, I need your help, I need your help. How can I convert this python programming code to C?
Set41
from numba import jit, cuda import numpy as np # to measure exec time from timeit import default_timer as timer # normal function to run on cpu def func(a): for i in range(10000000): a[i]+= 1 # function optimized to run on gpu @jit(target ="cuda") def func2(a): for i in range(10000000): a[i]+= 1 if name=="__main__": n = 10000000 a = np.ones(n, dtype = np.float64) b = np.ones(n, dtype = np.float32) start = timer() func(a) print("without GPU:", timer()-start) start = timer() func2(a) print("with GPU:", timer()-start)
shriman_deepak
Hey how to check if there's any space between string or not ?
shriman_deepak
I mean the proper syntax to use that function to check the space
Dr
Hey how to check if there's any space between string or not ?
Iterate through characters and check for ' '??
shriman_deepak
Any syntax ?
shriman_deepak
Just for reference
shriman_deepak
I never used that
ARx
strings are like arrays of chars string[i] == ' ' can be a good condition
Dr
Just for reference
Well I don't know any built in function to index any specific character from string, but as I said above for iterating through string, you can simply use for loop from i=0 to i=string.length() And check if string[i] == ' '
I use Arch
Just for reference
You can search info about std::string::find in the Internet
Dr
lol i just tried and it worked... wait
Dr
string s = "Hello World!"; for (int i=0; i<s.length(); i++) if (s[i] == ' ') cout<<"Space Found!"<<endl;
dave
does anybody speak italian and can help me in c++ base things
anonymous
I wanna learn c++ from beginning
artemetra 🇺🇦
Anonymous
The best way to learn C as a first language is through a book as your first language is the hardest language
Anonymous
They’re not comprehensive which is the problem
The
I am trying to compile my simple hello world app with via developer command line , but when add #include <string> to my test app throws many unliked externals
The
cmd used to compile: "cl /nologo /c /O1 test.cpp" -> "link /nologo /ENTRY:main /SUBSYSTEM:WINDOWS test.obj msvcrt.lib kernel32.lib user32.lib"
The
same app works fine if i compile on visual studio, so my guess cl.exe can't find standard libraries
The
what I doing wrong?
Anonymous
Don’t manually link the libraries
Anonymous
Install visual studio community 2022 or whatever is the latest version it comes with a compiler for c and c++
មួង អាទិត្យឆវ័ន្ត
/get
Anonymous
Hello people 👋
មួង អាទិត្យឆវ័ន្ត
sorry just accidently drop my mouse on comment
Dr
#india
Mr
/get
/notes
...
You are required to write down a program to calculate the area and volume of an office using Object Oriented Programming with C++. You should use the Office class and its object office1 to calculate the area and volume of the office. In the main(), you should assign the values of length, breadth, and height with the code: office1.length = 70 office1.breadth = 40 office1.height = 30 i. In the written program(s), demonstrate the use of both public and private members/objects of a class in the program(s). [8marks] ii. Compile the program using a suitable simulator e.g. Code::Blocks and debug all errors and take a screen shot. [4marks]
Anonymous
Use msvc
cl is part of the msvc, wdym?
Anonymous
cli is but its hard to use cli on msvc its hell even trying to find where its located
Anonymous
Back when I used windows i used visual studio community 2019
Anonymous
/get rose_as_my_girlfriend
Anonymous
😳
Anonymous
cli is but its hard to use cli on msvc its hell even trying to find where its located
Should be in PATH and if not, it's added in the development console. Doesn't matter, so what you tried to say was "use msvs" not "use msvc".
Anonymous
Good morning
Anonymous
I'm not really sure if there are anyways to get MSVC compiler besides Visual Studio Community
Anonymous
DOS commands are hard to use for me
Anonymous
DOS commands are hard to use for me
You just type stuff inside a black screen. On Linux you are even more dependant on it.
Anonymous
you can set it up manually with vscode
Anonymous
gcc is easier to use in my opinion
Anonymous
They have very similar flags ig, so not sure why u say that
Anonymous
gcc has too many flags to count lol
Anonymous
Also cl.exe has many
Anonymous
always have -Wall :)
Anonymous
its a linker like ld so yeah
Anonymous
https://docs.microsoft.com/en-us/cpp/build/reference/compiler-options?view=msvc-160
Anonymous
found documentation on it cl controls C/C++ compiler
Anonymous
"You can start this tool only from a Visual Studio developer command prompt. You cannot start it from a system command prompt or from File Explorer. For more information, see Use the MSVC toolset from the command line." does this mean you have to install visual studio community?
Adarsh
#include<iostream> #include<stdlib.h> using namespace std; struct node { int data; struct node *next; }*first; void create(int a[],int size) { int i=0; struct node *t,*last; first=new node; first->data=a[i]; first->next=NULL; last=first; for(i=1;i<size;i++) { t=new node; t->data=a[i]; t->next=NULL; last->next=t; last=t; } } void Display(struct node *t) { while(t) { cout<<t->data<<" "; t=t->next; } } int count(struct node *p) { int count=0; while(p) { count++; p=p->next; } } void Insert(struct node *p,int position,int x) { struct node *t=new node; t->data=x; if(position<0||position>count(p))return; if(position==0) { t->next=first; first=t; } else { for(int i=0;i<position-1;i++)p=p->next; t->next=p->next; p->next=t; } } int main() { int a[]={1,9,3,7,6,4,5,2,8}; create(a,9); Display(first); cout<<endl; Insert(first,5,100); Display(first); cout<<endl; return 0; }
Adarsh
can anyone tell me my error i cannot insert a new node at any index other than 0
Dr
Also I read somewhere, you should use nullptr instead of NULL for pointers
Adarsh
thank you to both of you it is working fine now
Anshul
Also I read somewhere, you should use nullptr instead of NULL for pointers
What's the difference? I have been using NULL everywhere in my c++ code never used nullptr
I use Arch
NULL is 0. When you use 0 to set the value of pointer it automatically convertes to nullptr as I know
Anonymous
What's the difference? I have been using NULL everywhere in my c++ code never used nullptr
I dont remember why, but it's something with the cpp stdlib
Arvind
I don't remember seeing a nullptr.
I use Arch
I think using both is fine
Yes but using nullptr may be little faster and more readable
Anonymous
https://stackoverflow.com/a/20509811
Anonymous
But u can still use NULL/0