当前位置:网站首页>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边栏推荐
- Class exercises
- 多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
- [combinatorics] exponential generating function (properties of exponential generating function | exponential generating function solving multiple set arrangement)
- 论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
- 2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
- TypeScript 官网教程
- Module 9 operation
- How to disable the clear button of ie10 insert text box- How can I disable the clear button that IE10 inserts into textboxes?
- Multifunctional web file manager filestash
- [combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
猜你喜欢
Prototype inheritance..
Computer graduation design PHP campus address book telephone number inquiry system
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
2022-2028 global physiotherapy clinic industry research and trend analysis report
win32:堆破壞的dump文件分析
How to track the real-time trend of Bank of London
English語法_名詞 - 分類
Have you learned the correct expression posture of programmers on Valentine's day?
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals
随机推荐
Opencv learning notes (continuously updated)
Win32: dump file analysis of heap corruption
Redis on local access server
Redis core technology and practice - learning notes (11): why not just string
A. Odd Selection【BruteForce】
How to draw non overlapping bubble chart in MATLAB
[tutorial] build your first application on coreos
[combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
Bidding procurement scheme management of Oracle project management system
How many convolution methods does deep learning have? (including drawings)
PHP MySQL inserts data
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
[combinatorics] exponential generating function (example 2 of solving multiple set permutation with exponential generating function)
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
[linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available
Kratos微服务框架下实现CQRS架构模式
189. Rotation array
English grammar_ Adjective / adverb Level 3 - multiple expression
How to disable the clear button of ie10 insert text box- How can I disable the clear button that IE10 inserts into textboxes?