[Solved] can’t understand “std::cout”

The code presented by you in a C++ program. You need to save it in file.cpp format, after that you need to compile with g++ file.cpp and it should work. You have saved it file.c format and compiling it with gcc, which is C standard, not C++. solved can’t understand “std::cout”

[Solved] why the array is static [closed]

The function isn’t the pointer. The return value is int * since it returns an array of int. You need a pointer to access an array. If it’s not a pointer, then you are expecting a single int variable. If it’s not static, then the array will be deallocated and gone when the function reached … Read more

[Solved] How can I read and process this kind of file [closed]

You can do this with file operations in c, i am just giving you hints, FILE *pFilePtr; // file pointer(handle of file) pFilePtr = fopen(argv[1],”r”); //define buffer to store data read line by line data char buf[32]={0}; //Now you can run a while loop to read entire file with fread() to get whole first line(until … Read more

[Solved] Stuck in infinite fgets loop

If there are more than one statements that you want to write in a loop or if statement, then you must use braces {} to define which statements come in the loop. In your code, only the printf(“Insert a non negative number: “); statement is in the loop, and nothing is changing the input‘s value … Read more

[Solved] How to inverse string without library functions – C++

Did you maybe mean to do this: for (int i = 0; i < userString.length(); ++i) { if (isupper(userString[i])) { userString[i] = (tolower(userString[i])); } else if(islower(userString[i])) { userString[i] = (toupper(userString[i])); } } This will actually inverse. What you were doing before doesn’t work, and also only converts to uppercase 11 solved How to inverse string … Read more

[Solved] Use long** instead of char** in C main argument

I tested this on the server (I AM NOT ABLE TO RUN THIS CODE ON MY MACHINE). And apparently, the parameter a is stored in stack like char. If I am calling my program like this ./a 12345678 and print out *a[1] as long in hex format, I got the value 0x3837363534333231 I will say … Read more

[Solved] Multiple ternary operators and evaluating int as boolean mystery [closed]

Why does any combination of true and false return the value it does? There is no combination of any boolean here. This ?: operator returns first or second expression, not the condition itself. condition ? first_expression : second_expression; The condition must evaluate to true or false. If condition is true, first_expression is evaluated and becomes … Read more

[Solved] C++ does not name a type error in Codeblocks [duplicate]

You can’t put arbitrary statements at the file scope in C++, you need to put them in a function. #include <string> #include <fstream> #include <streambuf> #include <sstream> int main () { //These are now local variables std::ifstream t(“C:/Windows/System32/drivers/etc/hosts-backup.txt”); std::stringstream buffer; //We can write expression statements because we’re in a function buffer << t.rdbuf(); } 4 … Read more

[Solved] Why doesn’t `bar` in this code have static storage duration?

You are confusing the scope of a variable with the storage duration. As mentioned in the C11 standard, chapter ยง6.2.1, Scopes of identifiers, for file scope […] If the declarator or type specifier that declares the identifier appears outside of any block or list of parameters, the identifier has file scope, which terminates at the … Read more

[Solved] C++ declaring variable and console [closed]

The problem here is that you are trying to print the length before taking an input. The cout<<length will print a garbage value since length hasn’t been assigned yet. Try this instead. Also don’t use using namespace std; #include<iostream> int main(){ int length; std::cout << “Input length of a square in centimeter “; std::cin >> … Read more