C++ Code Examples for read input file
22 C++ code examples are found related to "read input file".
These examples are extracted from open source projects.
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
Project: WebRTC-APM-for-Android Author: dengzikun File: input_audio_file.cc License: Apache License 2.0 | 6 votes |
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 2
Project: ClothDesigner Author: dolphin-li File: main.cpp License: MIT License | 6 votes |
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
Project: nipper-ng Author: arpitn30 File: nipper-common.c License: GNU General Public License v3.0 | 6 votes |
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 4
Project: Code Author: demonsaw File: file.cpp License: MIT License | 6 votes |
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
Project: Learning-OpenCV-3-Application-Development Author: PacktPublishing File: markEyeLocations.cpp License: MIT License | 6 votes |
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 6
Project: Code Author: demonsaw File: file_util.cpp License: MIT License | 6 votes |
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
Project: Algo_Ds_Notes Author: jainaman224 File: Ford-Fulkerson.cpp License: GNU General Public License v3.0 | 6 votes |
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 8
Project: WebRTC-APM-for-Android Author: dengzikun File: resample_input_audio_file.cc License: Apache License 2.0 | 6 votes |
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
Project: TeamTalk Author: balloonwj File: main.cpp License: Apache License 2.0 | 6 votes |
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 10
Project: WebRTC-APM-for-Android Author: dengzikun File: debug_dump_test.cc License: Apache License 2.0 | 6 votes |
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 11
Project: patrace Author: ARM-software File: main.cpp License: MIT License | 6 votes |
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 12
Project: Code Author: demonsaw File: file_component.cpp License: MIT License | 6 votes |
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 13
Project: catboost Author: catboost File: zero_copy_stream_impl.cc License: Apache License 2.0 | 5 votes |
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 14
Project: Undergraduate Author: Trinkle23897 File: zero_copy_stream_impl.cc License: MIT License | 5 votes |
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 15
Project: game_net Author: huailiang File: zero_copy_stream_impl.cc License: MIT License | 5 votes |
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 16
Project: thu-cst-cracker Author: Salensoft File: zero_copy_stream_impl.cc License: MIT License | 5 votes |
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 17
Project: echo Author: timi-liuliang File: zero_copy_stream_impl.cc License: MIT License | 5 votes |
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 18
Project: DataCore Author: quantOS-org File: zero_copy_stream_impl.cc License: Apache License 2.0 | 5 votes |
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 19
Project: echo Author: timi-liuliang File: ImfInputFile.cpp License: MIT License | 5 votes |
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 20
Project: smefs-Indigo-Remastered Author: smefpw File: zero_copy_stream_impl.cc License: MIT License | 5 votes |
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 21
Project: BattleServer Author: tsymiar File: zero_copy_stream_impl.cc License: The Unlicense | 5 votes |
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 22
Project: CRP Author: michaelwegner File: MultiLevelPartition.cpp License: MIT License | 5 votes |
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); } } }