For reading from an xml file,

char s[6];
ifstream x("output.xml");
x.getline(s,34);

char s[6];
I don't want to specify the maximum number of characters in 's'.So,I tried to use string s instead,but getline only takes character arrays.
When I used char*,it said,The variable 's' is being used without being initialized.
So,how do I use a character array that has no maximum number of characters(limit)??????

Recommended Answers

All 2 Replies

The <string> header provides a global getline() that does what you need i.e. it works with std::string .
For example

#include <string>
#include <fstream>
#include <iostream>
int main()
{
  std::ifstream ifs("file.txt");
  std::string s;

  while(getline(ifs, s))
  {
    std::cout << s << std::endl;
  }

  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.