Horje
C++ file . Code Example
c++ files
// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile.close();
  return 0;
}
C++ file .
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>

/*
Premise:

We have a top secret file that only authorized users are allowed to download, and they need a CLI tool for retrieving it.
We tasked a developer with building the server and client for this.
He built the client first, and has sent you his code for review.

What feedback, questions, or concerns would you give the developer after reviewing his client.

*/
bool userIsFound(std::string query)
{
  // Pretend this method actually executes an SQL query instead of always returning true
  return true;
}

void fetchHttpFile(std::string url)
{
  // Pretend the code for this lives somewhere else
}

int main (int argc, char* argv[])
{
  char username[20];
  char password[20];
  strcpy(username, argv[1]);
  strcpy(password, argv[2]);

  std::string query = "SELECT * FROM users WHERE username=" + std::string(username) + " AND password=" + std::string(password);
  std::string url = "http://secretuser:secretpassword@www.example.com/secretfile";

  if (userIsFound(query)) {
    fetchHttpFile(url);
    std::cout << "Downloading file: " + url;
    exit (EXIT_SUCCESS);
  }
  else
  {
    std::cout << "Error downloading file: " + url + " You do not have permission.";
    exit (EXIT_FAILURE);
  }
}




Cpp

Related
TypeScript Code Example TypeScript Code Example
print maximum sum subarray Code Example print maximum sum subarray Code Example
Check whether K-th bit is set or not c++ Code Example Check whether K-th bit is set or not c++ Code Example
extra parameter in comparator function for sort Code Example extra parameter in comparator function for sort Code Example
is power of 2 Code Example is power of 2 Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7