Hello,
I'm trying to get a string from a thing that is inside quotes as you can see here, but when i try to compile i got this errors:
ubuntu@eeepc:~/C++/Tree$ g++ -o tree tree.cpp
tree.cpp: In function ‘int main(int, char**)’:
tree.cpp:65: error: ‘get’ was not declared in this scope
tree.cpp:65: error: expected ‘,’ or ‘;’ before ‘file’
tree.cpp:66: error: ‘struct std::string’ has no member named ‘indexOf’
tree.cpp:66: error: ‘copy_input’ was not declared in this scope
tree.cpp:67: error: ‘struct std::string’ has no member named ‘indexOf’
tree.cpp:69: error: ‘struct std::string’ has no member named ‘substring’
tree.cpp:70: error: ‘struct std::string’ has no member named ‘indexOf’
tree.cpp:71: error: ‘struct std::string’ has no member named ‘indexOf’
tree.cpp:73: error: ‘struct std::string’ has no member named ‘substring’
ubuntu@eeepc:~/C++/Tree$
And here is the code of my program:
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main( int argc, char* argv[] )
{
// Error Messages
string extension = argv[ 1 ];
if(argc != 2)
{
cout << "Error syntax is incorrect!\nSyntax: " << argv[ 0 ] << " <file>\n";
return 0;
}
if(extension[extension.length()-3] != '.')
{
cout << "Extension not valid!" << endl;
cout << "Default extension *.tr" << endl;
return 0;
}
if(extension[extension.length()-2] != 't')
{
cout << "Extension not valid!" << endl;
cout << "Default extension *.tr" << endl;
return 0;
}
if(extension[extension.length()-1] != 'r')
{
cout << "Extension not valid!" << endl;
cout << "Default extension *.tr" << endl;
return 0;
}
// End of the error messages
ifstream file(argv[ 1 ]);
if (!file.good()) {
cout << "File " << argv[ 1 ] << " does not exist.\n";
return 0;
}
string linha;
while (!file.eof())
{
getline(file, linha);
if (linha.find("print") != string::npos)
{
size_t idx = linha.find("\""); //find the first quote on the line
while ( idx != string::npos )
{
size_t idx_end = linha.find("\"",idx+1); //end of quote
string quotes;
quotes.assign(linha,idx,idx_end-idx+1);
// do not print the start and end " strings
cout << quotes.substr(1,quotes.length()-2) << endl;
//check for another quote on the same line
idx = linha.find("\"",idx_end+1);
}
}
if (linha.find("copy_input") != string::npos)
{
string file = get file;
int start = file.indexOf(copy_input);
int end = file.indexOf("\n", start);
string line = file.substring(start, end);
int quoteStart = line.indexOf("\"");
int quoteEnd = line.indexOf("\"", quoteStart);
string quotes = line.substring(quoteStart, quoteEnd);
cout << quotes << endl;
}
}
return 0;
}
What i'm doing wrong?
Thanks,
Nathan Paulino Campos