Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ open file

// Reading a file

#include <iostream>
#include <fstream>
#include <string>

int main() 
{
    std::string line;

    std::ifstream file("example.txt");
    if(file.is_open())
    {
        while(getline(file, line))
        {
            std::cout << line << '
';
        }
        file.close();
    }
    else std::cout << "Unable to open file";

    return 0;
}
Comment

file open cpp

#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  myfile.open ("file.txt");
  myfile << "Writing to a file.
";
  myfile.close();
  return 0;
}
Comment

c++ read file

#include <stdio.h>

#define n 1024 // n bytes

int main(void) {
	FILE *fp;
    size_t numread;
    if ((fp = fopen("yourfile.xy", "rb") != NULL) {
    	char buffer[n];
        numread = fread(buffer, sizeof(*buffer), n, fp);
      	printf("Read %d Bytes: %s", numread, buffer);
      
      	fclose(fp);
      	return 0;
    }
        
    return -1;
}
Comment

files c++

fstream  afile;
afile.open("file.dat", ios::out | ios::in );
Comment

PREVIOUS NEXT
Code Example
Cpp :: operands c++ 
Cpp :: cpp macro 
Cpp :: 2d vector cpp 
Cpp :: roscpp publish int32 
Cpp :: how to add colored text in c++ 
Cpp :: C++ switch - case - break 
Cpp :: http.begin arduino not working 
Cpp :: how to write something in power of a number in c++ 
Cpp :: set precision with fixed c++ 
Cpp :: string vector c++ 
Cpp :: loop through a vector in c++ 
Cpp :: singleton c++ 
Cpp :: max of a vector c++ 
Cpp :: Write C++ program to sort an array in ascending order 
Cpp :: return array from function c++ 
Cpp :: c++ prime sieve 
Cpp :: How to pause a c++ program. 
Cpp :: c++ greatest common divisor 
Cpp :: increment c++ 
Cpp :: sort a 2d vector c++ stl 
Cpp :: size of stack in c++ 
Cpp :: C++ String Length Example 
Cpp :: c++ cout format 
Cpp :: c++ array size 
Cpp :: cannot jump from switch statement to this case label c++ 
Cpp :: c++ program to print natural numbers from 1 to 10 in reverse order using while loop 
Cpp :: c++ hashmaps 
Cpp :: array to string c++ 
Cpp :: c++ string find example 
Cpp :: print two dimensional array c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =