Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // C++ File IO (what I need)
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- /*
- * Main function.
- */
- int main(int argc, char** argv) {
- std::string file_name = argv[1];
- std::ifstream inf(file_name);
- if (!inf) {
- std::cerr << "uhoh cannot read file!" << std::endl;
- }
- while (inf) {
- std::string text;
- std::getline(inf, text);
- std::cout << text << std::endl;
- }
- return 0;
- }
- // C File IO (what I need)
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- /*
- * The main function.
- */
- int main(int argc, char** argv) {
- if (argc == 2) {
- printf("\nArgument: %s\n", argv[1]);
- FILE *fp = fopen(argv[1], "r");
- if (fp != NULL) {
- char output[50] = "";
- char other_output[] = "Error!";
- puts("Going to print out the data");
- while (!feof(fp)) {
- fgets(output, 50, fp);
- }
- fclose(fp);
- printf("%s", output);
- }
- } else if (argc > 2) {
- printf("Too many commands supplied.\n");
- } else {
- printf("Not enough commands supplied.\n");
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement