#include <iostream>
#include <string>
#include <vector>
/*
Using STL's string class because the problem does not refer any
limits regarding the number of characters per line.
*/
using namespace std;
int main()
{
string line;
vector<string> lines;
while (getline(cin, line))
{
lines.push_back(line);
}
unsigned int i, u;
unsigned int opening = 1; // 2 if last was opening, 1 if it was closing
for (i = 0; i < (int) lines.size(); i++)
{
for (u = 0; u < (int) lines[u].length(); u++)
{
}
}
return 0;
}
मेरे पास है कि सरल कोड है कि बस कुछ ही लाइनों पर पढ़ता है (इनपुट फ़ाइल):एसटीएल स्ट्रिंग :: लंबाई() segfaulting
"To be or not to be," quoth the Bard, "that
is the question".
The programming contestant replied: "I must disagree.
To `C' or not to `C', that is The Question!"
हालांकि, मैंने पाया के रूप में यह एक पढ़ता है कि यह segfaulting है '' (स्पेस) पहली पंक्ति (4 चरित्र) पर चरित्र:
(gdb) run < texquotes_input.txt
Starting program: /home/david/src/oni/texquotes < texquotes_input.txt
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b92533 in std::string::length() const() from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
मैं सच में समझ में नहीं आता क्यों, मैं कुछ भी लूप के अंदर नहीं कर रहा हूँ, मैं सिर्फ पाशन कर रहा हूँ।
उत्कृष्ट "छोटे पूरा संकलित उदाहरण "। –
अंगूठे का नियम: यदि स्टडलिब में एक सेगफॉल्ट है तो आप शायद पढ़ रहे/लिख रहे/हटा रहे हैं जहां आपको नहीं करना चाहिए;)। –