Category : string

I’m using snprintf() to write string into a buffer. #define MAXLEN 256 char line[MAXLEN]; char buf[MAXLEN]; snprintf(buf, sizeof(buf), "Hi%s", line); When compiling, it shows warning directive writing up to 256 bytes into a region of size 254 Any better way to solve this? I don’t want to use malloc(…) or similar dynamic allocating function. Source: ..

Read more

Question : Find the number of "n"(new line character) present in any string. Input : String s = "Shroud isn a godlike player inn video gaming community." Output : 2 Here is my code : #include<bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int nseq=0; string s; cin>>s; for(int i=0;i<s.length()-1;i++) { if(s.substr(i,i+1)=="n") { nseq++; ..

Read more

hello guys i wrote this code : print("*"*78) def student_info(name,age,gender): print ("Student name : ",name) print ("Student age : ",age) print("Student gender : ",gender) sname=input("Enter your name : ") sage=input("Enter your age : ") sgender=input("Enter your gender : ") print("*"*78) print("press ‘1’ to print info ‘2’ for save") choice=input("Enter your choice : ") if choice=="1": ..

Read more

The compiler keeps saying "No instance of overloaded function "getline" matches the argument list" even though nothing is wrong as I have used this function before in exactly the same way without issues. Here is the code. #include<string> #include<iostream> using namespace std; int main() { string answer; cout << "!!!Bad network connection!!!n" "Reboot your computer ..

Read more

I am trying to make a vector that contains vectors, that contains a string. I am unsure on how I would go about retrieving said string. I’ve tried vector.at() but I’m not sure how to make a sort of ‘multi-layered’ version of it. This is the value inside of my code: std::vector<std::vector<std::string>> dialoguestore; Source: Windows ..

Read more