`read input file` C++ Examples

22 C++ code examples are found related to "read input file". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: nipper-common.c    From nipper-ng with GNU General Public License v3.0 11 votes vote down vote up
void readLine(FILE *input, char *lineFromFile, int maxLength)
{
	// Variables...
	int stripPointer = 0;

	// Read line from file...
	memset(lineFromFile, 0, maxLength);
	fgets(lineFromFile, maxLength, input);

	// Clear the end-of-line stuff...
	stripPointer = strlen(lineFromFile) -1;
	while ((lineFromFile[stripPointer] == '\r') || (lineFromFile[stripPointer] == '\n') || (lineFromFile[stripPointer] == ' '))
	{
		lineFromFile[stripPointer] = 0;
		stripPointer--;
	}
} 
Example 2
Source File: main.cpp    From TeamTalk with Apache License 2.0 5 votes vote down vote up
static std::string readInputTestFile(const char *path) {
  FILE *file = fopen(path, "rb");
  if (!file)
    return std::string("");
  fseek(file, 0, SEEK_END);
  long size = ftell(file);
  fseek(file, 0, SEEK_SET);
  std::string text;
  char *buffer = new char[size + 1];
  buffer[size] = 0;
  if (fread(buffer, 1, size, file) == (unsigned long)size)
    text = buffer;
  fclose(file);
  delete[] buffer;
  return text;
} 
Example 3
Source File: Ford-Fulkerson.cpp    From Algo_Ds_Notes with GNU General Public License v3.0 5 votes vote down vote up
void read_input_file() {
    int a,b,c,i,j;
    int ar[10]={0,0,1,2,3,1,2,4,3,4};
    int br[10]={1,2,2,1,2,3,4,3,5,5};
    int cr[10]={16,13,10,4,9,12,14,7,20,4};
    FILE* input = fopen("mf.in","r");
    // read number of nodes and edges
    //fscanf(input,"%d %d",&n,&e);
    // initialize empty capacity matrix 
    for (i=0; i<6; i++) {
	for (j=0; j<6; j++) {
	    capacity[i][j] = 0;
	}
    }
    // read edge capacities
    for (i=0; i<10; i++) {
	//fscanf(input,"%d %d %d",&a,&b,&c);
	a=ar[i];b=br[i];c=cr[i];
	capacity[a][b] = c;
    }
    fclose(input);
} 
Example 4
Source File: file.cpp    From Code with MIT License 5 votes vote down vote up
u64 file::read(std::string& input, u64 input_size /*= 0*/, u64 offset /*= 0*/) const
	{
		const auto path = m_path.string();
		std::ifstream ifs(path, std::ios::binary | std::ios::in);

		if (ifs.good())
		{
			if (offset > m_size)
				offset = 0;

			if ((input_size == 0) || (input_size + offset) > m_size)
				input_size = (m_size - offset);

			input.resize(static_cast<size_t>(input_size));
			ifs.seekg(offset, std::ios::beg);			
			ifs.read(&input[0], input.size());
			ifs.close();

			return ifs.gcount();
		}

		return 0;
	} 
Example 5
Source File: file_component.cpp    From Code with MIT License 5 votes vote down vote up
u64 file_component::read(std::string& input, u64 input_size /*= 0*/, u64 offset /*= 0*/) const
	{
		const auto path = m_path.string();
		std::ifstream ifs(path, std::ios::binary | std::ios::in);

		if (ifs.good())
		{
			if (offset > m_size)
				offset = 0;

			if ((input_size == 0) || (input_size + offset) > m_size)
				input_size = (m_size - offset);

			input.resize(static_cast<size_t>(input_size));
			ifs.seekg(offset, std::ios::beg);
			ifs.read(&input[0], input.size());
			ifs.close();

			return ifs.gcount();
		}

		return 0;
	} 
Example 6
Source File: file_util.cpp    From Code with MIT License 5 votes vote down vote up
u64 file_util::read(const boost::filesystem::path& path, std::string& input, u64 input_size /*= 0*/, u64 offset /*= 0*/)
	{
		std::ifstream ifs(path.string(), std::ios::binary | std::ios::in | std::ios::ate);

		if (ifs.good())
		{
			const u64 size = ifs.tellg();
			if (offset > size)
				offset = 0;

			if ((input_size == 0) || (input_size + offset) > size)
				input_size = (size - offset);

			input.resize(static_cast<size_t>(input_size));
			ifs.seekg(offset, std::ios::beg);
			ifs.read(&input[0], input.size());
			ifs.close();

			return ifs.gcount();
		}

		return 0;
	} 
Example 7
Source File: markEyeLocations.cpp    From Learning-OpenCV-3-Application-Development with MIT License 5 votes vote down vote up
void readInput(char* filePath) {
    
    ifstream fin;
    fin.open(filePath);
    
    string line;
    int counter = 0;
    
    while(getline(fin, line)) {
        
        counter = (counter + 1) % 3;
        if (counter == 1)
            imagePaths.push_back(line);
        else if (counter == 2) {
            Point leftEyeLoc = getCoordinates(line);
            leftEyeCoordinates.push_back(leftEyeLoc);
        }
        else { 
Example 8
Source File: resample_input_audio_file.cc    From WebRTC-APM-for-Android with Apache License 2.0 5 votes vote down vote up
bool ResampleInputAudioFile::Read(size_t samples,
                                  int output_rate_hz,
                                  int16_t* destination) {
  const size_t samples_to_read = samples * file_rate_hz_ / output_rate_hz;
  RTC_CHECK_EQ(samples_to_read * output_rate_hz, samples * file_rate_hz_)
      << "Frame size and sample rates don't add up to an integer.";
  std::unique_ptr<int16_t[]> temp_destination(new int16_t[samples_to_read]);
  if (!InputAudioFile::Read(samples_to_read, temp_destination.get()))
    return false;
  resampler_.ResetIfNeeded(file_rate_hz_, output_rate_hz, 1);
  size_t output_length = 0;
  RTC_CHECK_EQ(resampler_.Push(temp_destination.get(), samples_to_read,
                               destination, samples, output_length),
               0);
  RTC_CHECK_EQ(samples, output_length);
  return true;
} 
Example 9
Source File: debug_dump_test.cc    From WebRTC-APM-for-Android with Apache License 2.0 5 votes vote down vote up
void DebugDumpGenerator::ReadAndDeinterleave(ResampleInputAudioFile* audio,
                                             int channels,
                                             const StreamConfig& config,
                                             float* const* buffer) {
  const size_t num_frames = config.num_frames();
  const int out_channels = config.num_channels();

  std::vector<int16_t> signal(channels * num_frames);

  audio->Read(num_frames * channels, &signal[0]);

  // We only allow reducing number of channels by discarding some channels.
  RTC_CHECK_LE(out_channels, channels);
  for (int channel = 0; channel < out_channels; ++channel) {
    for (size_t i = 0; i < num_frames; ++i) {
      buffer[channel][i] = S16ToFloat(signal[i * channels + channel]);
    }
  }
} 
Example 10
Source File: ImfInputFile.cpp    From echo with MIT License 4 votes vote down vote up
void
bufferedReadPixels (InputFile::Data* ifd, int scanLine1, int scanLine2)
{
    //
    // bufferedReadPixels reads each row of tiles that intersect the
    // scan-line range (scanLine1 to scanLine2). The previous row of
    // tiles is cached in order to prevent redundent tile reads when
    // accessing scanlines sequentially.
    //

    int minY = std::min (scanLine1, scanLine2);
    int maxY = std::max (scanLine1, scanLine2);

    if (minY < ifd->minY || maxY >  ifd->maxY)
    {
        throw Iex::ArgExc ("Tried to read scan line outside "
			   "the image file's data window.");
    }

    //
    // The minimum and maximum y tile coordinates that intersect this
    // scanline range
    //

    int minDy = (minY - ifd->minY) / ifd->tFile->tileYSize();
    int maxDy = (maxY - ifd->minY) / ifd->tFile->tileYSize();

    //
    // Figure out which one is first in the file so we can read without seeking
    //

    int yStart, yEnd, yStep;

    if (ifd->lineOrder == DECREASING_Y)
    {
        yStart = maxDy;
        yEnd = minDy - 1;
        yStep = -1;
    }
    else
    { 
Example 11
Source File: zero_copy_stream_impl.cc    From echo with MIT License 4 votes vote down vote up
int FileInputStream::CopyingFileInputStream::Read(void* buffer, int size) {
  GOOGLE_CHECK(!is_closed_);

  int result;
  do {
    result = read(file_, buffer, size);
  } while (result < 0 && errno == EINTR);

  if (result < 0) {
    // Read error (not EOF).
    errno_ = errno;
  }

  return result;
} 
Example 12
Source File: MultiLevelPartition.cpp    From CRP with MIT License 4 votes vote down vote up
void MultiLevelPartition::read(const std::string &inputFileName) {
	std::ifstream file;
	file.open(inputFileName);
	if (file.is_open()) {
		std::string line;
		getline(file, line);

		count numLevels = std::stoi(line);
		numCells = std::vector<count>(numLevels);
		for (index i = 0; i < numLevels; ++i) {
			std::getline(file, line);
			numCells[i] = std::stoi(line);
		}

		computeBitmap();

		std::getline(file, line);
		count numVertices = std::stoi(line);

		cellNumbers = std::vector<pv>(numVertices);
		for (index i = 0; i < numVertices; ++i) {
			std::getline(file, line);
			cellNumbers[i] = std::stoull(line);
		}
	}
} 
Example 13
Source File: input_audio_file.cc    From WebRTC-APM-for-Android with Apache License 2.0 2 votes vote down vote up
bool InputAudioFile::Read(size_t samples, int16_t* destination) {
  if (!fp_) {
    return false;
  }
  size_t samples_read = fread(destination, sizeof(int16_t), samples, fp_);
  if (samples_read < samples) {
    // Rewind and read the missing samples.
    rewind(fp_);
    size_t missing_samples = samples - samples_read;
    if (fread(destination + samples_read, sizeof(int16_t), missing_samples,
              fp_) < missing_samples) {
      // Could not read enough even after rewinding the file.
      return false;
    }
  }
  return true;
} 
Example 14
Source File: main.cpp    From ClothDesigner with MIT License 0 votes vote down vote up
static std::string
readInputTestFile( const char *path )
{
   FILE *file = fopen( path, "rb" );
   if ( !file )
      return std::string("");
   fseek( file, 0, SEEK_END );
   long size = ftell( file );
   fseek( file, 0, SEEK_SET );
   std::string text;
   char *buffer = new char[size+1];
   buffer[size] = 0;
   if ( fread( buffer, 1, size, file ) == (unsigned long)size )
      text = buffer;
   fclose( file );
   delete[] buffer;
   return text;
}