-1
I need to make a program in c++ that reads a multi-line input and stores each line(string) in an array.
I’ve tried using the cin.eof()
and fgets()
but it didn’t work.
#include<iostream>
#include<string>
using namespace std;
int main()
{
string entrada;
cin >> entrada;
while(!cin.eof())
{
cout << "Entrada ainda não terminou." << endl;
cin.ignore();
getline(cin, entrada);
cout << entrada << endl;
}
cout << "Entrada terminou." << endl;
return 0;
}
Anyone can help?
How’s the code you tried so far?
– Leonel Sanches da Silva
[#include<iostream> #include<string> using namespace Std; int main(){ string input; Cin >> input; while(!Cin.eof()){ Cout << "Input not finished yet." << Endl; Cin.ignore(); getline(Cin, input); Cout << input << Endl; } Cout << "Input finished." << Endl; ;}]
– Leonardo
Is there any way to specify that my comment is a code? This is my first time doubting it here.
– Leonardo
Usually editing your question. Here’s how I edited it. Four spaces in the front indicate to Markdown that it’s code.
– Leonel Sanches da Silva
Something else: Take a walk here, to understand how the site works.
– Leonel Sanches da Silva
I’ll look yes, thank you!
– Leonardo