当前位置:网站首页>Reading a line from ifstream into a string variable
Reading a line from ifstream into a string variable
2022-07-03 18:35:00 【Bustling city 】
problem :
In the following code : In the following code :
#include <iostream>#include <fstream>#include <string>using namespace std;int main() { string x = "This is C++."; ofstream of("d:/tester.txt"); of << x; of.close(); ifstream read("d:/tester.txt"); read >> x; cout << x << endl ;}
Output :
This
Since >> operator reads upto the first whitespace i get this output. because >> operator Read the first space , I got this output .How can i extract the line back into the string ? How to lift the line Retrieve the string ?
I know this form of istream& getline (char* s, streamsize n );
I know this form istream& getline (char* s, streamsize n );
but i want to store it in a string variable. But I want to store it in a string variable .How can i do this ? How can I do this ?
Solution :
Reference resources : https://stackoom.com/en/question/RxNr边栏推荐
猜你喜欢
English grammar_ Adjective / adverb Level 3 - multiple expression
AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
How do microservices aggregate API documents? This wave of operation is too good
CV in transformer learning notes (continuously updated)
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
Bidding procurement scheme management of Oracle project management system
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
The vscode code is automatically modified to a compliance code when it is formatted and saved
随机推荐
[linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available
Module 9 operation
A. Odd Selection【BruteForce】
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
How do microservices aggregate API documents? This wave of operation is too good
Multifunctional web file manager filestash
Shell script return value with which output
Torch learning notes (5) -- autograd
Unsafe类的使用
[tutorial] build your first application on coreos
SDNUOJ1015
JS_ Array_ sort
PHP MySQL inserts data
Redis cache avalanche, penetration, breakdown
[combinatorics] exponential generating function (proving that the exponential generating function solves the arrangement of multiple sets)
Change the single node of Postgres database into master-slave
204. Count prime
2022-2028 global scar care product industry research and trend analysis report
042. (2.11) do it when it's time to do it
2022-2028 global petroleum pipe joint industry research and trend analysis report