Anonymous
@sam_1208 you need to fflush(stdin) before fgets
That just might work... That would clear the file buffer (including newlines). Good idea!
olli
@sam_1208 you need to fflush(stdin) before fgets
No, never flush stdin! That's UB
Avique
basic question that is not clear in the book/tutorial i am using: if i write just a class in a file, without anything outside it, is it expected that g++ complains about main() ? i want to write a class in a cpp file, a header with its public parts (can i omit the private things in the header file?), and keep this couple of files to be used by other programs. g++ error message: $ g++ j.cpp /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start': (.text+0x20): undefined reference to `main' collect2: error: ld returned 1 exit status $
AHMED
#include <iostream> #include <vector> using namespace std; int main() { int el; vector<int> v = {1, 2, 3, 4, 5}; for (int el : v) { el = el + el + el; cout << el << "\n"; } cout << "========\n"; for (int el : v) { cout << el << "\n"; } return 0; }
AHMED
Why does the second for loop display the original vector elements?
WHITE
Why does the second for loop display the original vector elements?
because the elements are passed by value in the first for loop use for(int &el:v)
AHMED
olli
So what should I do
there are different options, fgets only reads the single new line that is still left in the input stream. you could use fseek(stdin, 0, SEEK_END); to ignore the remaining part of the input stream
KING EZ
Please am a primer in c++. Am trying to run "Hello World" but in not responding. Please any help from a good Samaritan
Aakash
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() { char ch; char s[100]; char sen[100]; printf("\nEnter char"); scanf("%c",&ch); printf("Enter word\n"); scanf("%s",s); printf("Enter sentence\n"); fflush(stdin); fgets(sen,sizeof(sen), stdin); printf("%c\n",ch); printf("%s\n",s); puts(sen); return 0; }
This is how its done!! — #include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char ch; printf("Enter char:\n "); scanf(" %c", &ch); //always keep a blank before %c char s[100]; printf("Enter word:\n "); scanf(" %s",s); //same blank applies for %s; but not necessary, rather good practice until novice. char sen[100]; printf("Enter sentence:\n "); while(strlen(fgets(sen, 100, stdin))==1); //loop till you hit next line as 1:length.. printf("char: %c\n",ch); printf("word: %s\n",s); printf("sen : "); puts(sen); return 0; } ——stdin:I/O—- Enter char: t Enter word: test Enter sentence: this is how it works! char: t word: test sen : this is how it works! Enjoy🙃
Aakash
What have you done in the while loop
Nothing! Just strlen() terminated with ‘;’
Sam
Umm okay
Sam
Thx
AHMED
I don't understand move constructors and move assignment operators. Can anyone explain them to me please? Thanks in advance.
Vineeth
Hello, can anyone help me in writing a serial communication code for esp32 wifi development board
Ishikawa
Is there a way to use value of variable as identifier?
Ishikawa
Is there a way this string var ="cout <<\"hello\"<<endl;"; var; can do same as cout << "hello" <<endl;
Ishikawa
please elaborate
Ishikawa
std::map lmao
Can you please elaborate
Vlad
Can you please elaborate
std::map<std::string, Foo> map; auto it = map.find("bar"); if(it != map.end()) { // then value exists Foo& f = *it; }
Anonymous
/admin
/admin
Ishikawa
I'm actually trying to write a function to which identifiers could be passed in some way. Coming from BASH, I thought it could be done with similar ease, but I will leave it I guess. THANK YOU FOR HELPING.
Henry
Admin
Anonymous
Anyone know how to make a condition from output of a system function?
Santhu
Can any one teach me c language
Anonymous
Can any one teach me c language
We could point you to books tutorials and lectuure notes... Long-term tutoring is a bit much to ask.
Santhu
Bcs I don't no any I want learn
Alex
Anyone know how to make a condition from output of a system function?
https://stackoverflow.com/questions/646241/c-run-a-system-command-and-get-output
Anonymous
Bcs I don't no any I want learn
First thing is to aquire a computer and install a C compiler and text editor (maybe pre-installed). There are some coding apps available if your computer is an Android tablet.
Santhu
Can any one teach me c language
Any one teach me from basics
Vlad
Any one teach me from basics
Just get a book and learn lmao. Nobody's gonna spoon feed you
Anonymous
Any one teach me from basics
Installing basic tools can be easy or quite the hurdle, it all depends...
Santhu
Okk
Santhu
Okk
Santhu
Can u say how to write a program to implement a EMI calculator
Anonymous
https://stackoverflow.com/questions/646241/c-run-a-system-command-and-get-output
Can I DM you? I have my code in pastebin link but not permitted to send here
라이트
How to get system drive name like "C:\\" ? Exactly I'd like to get "C:\\ProgramData\\" path.
Anonymous
How to get system drive name like "C:\\" ? Exactly I'd like to get "C:\\ProgramData\\" path.
Modern versions of Windows should accept "/" as path seperator also (even if CMD.EXE might not), if you wanted to avoid escaping. Or maybe the path is in an environment variable accessible with getenv() from <stdlib.h>? https://man7.org/linux/man-pages/man3/getenv.3.html
Henry
Please how do i use pow() in linux it responding with error
라이트
Please how do i use pow() in linux it responding with error
https://linux.die.net/man/3/pow Good luck!
라이트
Can %ALLUSERSPROFILE% be changed?
Anonymous
https://linux.die.net/man/3/pow Good luck!
#include <math.h> On some platforms you need to explicitly link with math library too (-lm).
Anonymous
How can we execute a command if loops fail because of operation not permitted? I'm trying to make a condition from that specific output but still don't understand
Anonymous
Implementation plz.
I already write the code, can you take a look at it?
라이트
Welcome a new friend.
Vignesh
Hi
라이트
Hi
Hi
Aakash
doesn't work if you add a space after the word
Dude!!! I cannot help you with understanding of scanf() format specifiers.. You may replace the code with following.. that shall solve your problem. — ... printf("Enter word:\n "); scanf(" %[^\n]%s", s); ... Enjoy🙃
라이트
I'd like to get windows environment path with WinAPI, like SHGetSpecialFolderPathW(..)
MRT
i create native makefile(cmake) for my flutter project, i can build with cmake completly but with gradle i get Error C/C++ debug|armeabi-v7a : CMake Error: The following variables are used in this project, but they are set to NOTFOUND. Please set them or make sure they are set and tested correctly in the CMake files: CRYPTOPP_LIB linked by target "MD5test" in directory C:/Users/MrHaydari/Downloads/cryptopp-master/build
MRT
CmakeList.text
MRT
CmakeList.text
cmake_minimum_required (VERSION 3.15) # this enables the MSVC_RUNTIME_LIBRARY property for slightly older CMake versions cmake_policy(SET CMP0091 NEW) project ("MD5test") add_executable(MD5test "src/main.cpp") # this is equivalent to setting C/C++ -> Code Generation -> Runtime Library in the Visual Studio project property pages set_property(TARGET MD5test PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>") find_library(CRYPTOPP_LIB cryptlib.lib HINTS C:/Users/MrHaydari/Downloads/cryptopp-master/cryptopp-master/x64/Output/*) target_link_libraries(MD5test PUBLIC "${CRYPTOPP_LIB}") target_include_directories(MD5test PUBLIC "C:/Users/MrHaydari/Downloads/cryptopp-master/cryptopp-master")
라이트
What is the best way to read text from file?
라이트
I often use CStdioFile::ReadString()
Anonymous
Hy
Anonymous
Anybody knew about operator overloading