当前位置:网站首页>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边栏推荐
- 2022-2028 global lithium battery copper foil industry research and trend analysis report
- Sepconv (separable revolution) code recurrence
- The vscode code is automatically modified to a compliance code when it is formatted and saved
- PHP MySQL inserts multiple pieces of data
- 图像24位深度转8位深度
- The second largest gay dating website in the world was exposed, and the status of programmers in 2022
- PHP MySQL order by keyword
- 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
- Redis on local access server
- 2022-2028 global petroleum pipe joint industry research and trend analysis report
猜你喜欢
Golang string (string) and byte array ([]byte) are converted to each other
Administrative division code acquisition
多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
2022-2028 global physiotherapy clinic industry research and trend analysis report
Redis core technology and practice - learning notes (IX): slicing cluster
On Data Mining
How do microservices aggregate API documents? This wave of operation is too good
Raft 日志复制
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
随机推荐
Valentine's day, send you a little red flower~
Theoretical description of linear equations and summary of methods for solving linear equations by eigen
虚拟机和开发板互Ping问题
Sepconv (separable revolution) code recurrence
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
CTO and programmer were both sentenced for losing control of the crawler
How to quickly view the inheritance methods of existing models in torchvision?
Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download
Nodejs (01) - introductory tutorial
4. Load balancing and dynamic static separation
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
Naoqi robot summary 27
Prototype inheritance..
Unsafe类的使用
Closure and closure function
Boost.Asio Library
Lesson 13 of the Blue Bridge Cup -- tree array and line segment tree [exercise]
English語法_名詞 - 分類
Grammaire anglaise Nom - Classification
Torch learning notes (4) -- torch's dynamic calculation diagram