get

/**#include

include

int main() {
std::ifstream file(“1.txt”);
char buffer[100];

if (file) {
// Read a chunk of data into buffer
file.get(buffer, sizeof(buffer),’1′);

// Output the number of characters actually read


This content originally appeared on DEV Community and was authored by 海前 王

/**#include

include

int main() {
std::ifstream file("1.txt");
char buffer[100];

if (file) {
    // Read a chunk of data into buffer
    file.get(buffer, sizeof(buffer),'1');

    // Output the number of characters actually read
    std::streamsize numChars = file.gcount();
    std::cout << "Number of characters read: " << numChars << std::endl;

    // Null-terminate the string and output it
    buffer[numChars] = '\0';
    std::cout << "Content read: " << buffer << std::endl;
}

return 0;

}

include

include

int main() {
// 创建一个包含文本的字符串流
std::istringstream input("Hello, world! This is a test.");

// 创建一个 stringbuf 对象来存储读取的内容
std::stringbuf sb;

// 从 input 流中读取字符,直到遇到字符 '!'
input.get(sb, '!');

// 获取读取的字符串
std::string result = sb.str();

// 输出结果
std::cout << "Read content: " << result << std::endl;

//this cannot change the string 
std::cout<<"\n"<<input.str();

return 0;

}
*/

include

int main() {
char ch;
while ((ch = std::cin.peek()) != '.' && ch != '\n') {
std::cin.get(ch);
std::cout << ch; // 打印读取的字符
}
return 0;
}


This content originally appeared on DEV Community and was authored by 海前 王


Print Share Comment Cite Upload Translate Updates
APA

海前 王 | Sciencx (2024-09-06T01:41:37+00:00) get. Retrieved from https://www.scien.cx/2024/09/06/get/

MLA
" » get." 海前 王 | Sciencx - Friday September 6, 2024, https://www.scien.cx/2024/09/06/get/
HARVARD
海前 王 | Sciencx Friday September 6, 2024 » get., viewed ,<https://www.scien.cx/2024/09/06/get/>
VANCOUVER
海前 王 | Sciencx - » get. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/09/06/get/
CHICAGO
" » get." 海前 王 | Sciencx - Accessed . https://www.scien.cx/2024/09/06/get/
IEEE
" » get." 海前 王 | Sciencx [Online]. Available: https://www.scien.cx/2024/09/06/get/. [Accessed: ]
rf:citation
» get | 海前 王 | Sciencx | https://www.scien.cx/2024/09/06/get/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.