当前位置:网站首页>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边栏推荐
- [combinatorics] generating function (commutative property | derivative property | integral property)
- The vscode code is automatically modified to a compliance code when it is formatted and saved
- Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
- Setinterval CPU intensive- Is setInterval CPU intensive?
- Count the number of pixel values in the image
- Typescript official website tutorial
- 编程中常见的 Foo 是什么意思?
- How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
- [tutorial] build your first application on coreos
- How to track the real-time trend of Bank of London
猜你喜欢

PHP MySQL inserts data

How to quickly view the inheritance methods of existing models in torchvision?

How to draw non overlapping bubble chart in MATLAB

2022-2028 global physiotherapy clinic industry research and trend analysis report

虚拟机和开发板互Ping问题

2022-2028 global petroleum pipe joint industry research and trend analysis report

Should I be laid off at the age of 40? IBM is suspected of age discrimination, calling its old employees "dinosaurs" and planning to dismiss, but the employees can't refute it

SQL injection -day16

Computer graduation design PHP makeup sales Beauty shopping mall

4. Load balancing and dynamic static separation
随机推荐
How to expand the capacity of golang slice slice
Multifunctional web file manager filestash
Image 24 bits de profondeur à 8 bits de profondeur
Boost.Asio Library
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
Redis cache avalanche, penetration, breakdown
2022-2028 global lithium battery copper foil industry research and trend analysis report
Win 11 major updates, new features love love.
Torch learning notes (3) -- univariate linear regression model (self training)
[combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
Install apache+php+mysql+phpmyadmin xampp and its error resolution
2022-2028 global petroleum pipe joint industry research and trend analysis report
Shell script return value with which output
Three gradient descent methods and code implementation
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
Bidding procurement scheme management of Oracle project management system
编程中常见的 Foo 是什么意思?
[combinatorics] exponential generating function (example of exponential generating function solving multiple set arrangement)
Should I be laid off at the age of 40? IBM is suspected of age discrimination, calling its old employees "dinosaurs" and planning to dismiss, but the employees can't refute it