![]() |
| ||
| Search through a file for a string Hi, I'm very new to C++ and was wondering how I would go about searching for a string (AT+COPS?) in a file and displaying everything to the right of the string, could someone point me in the direction of a guide cheers |
| ||
| Re: Search through a file for a string Open the file read it line by line as a string and then use a string api to search for the keyword. It is quite cumbersome homework I would say. |
| ||
| Re: Search through a file for a string The hardest part is opening the file, then it's just like reading input from cin: #include <fstream> |
| ||
| Re: Search through a file for a string Quote:
to assignt the output to a varaible would I do something like String copsoutput; copsoutput = line.substr(start); I'm more of a visual baic & c# man, and wish my project would let write it in VB or C# cheers |
| ||
| Re: Search through a file for a string >> I'm more of a visual baic & c# man, and wish my project would let write it in VB or C# This is c++ board. If you want vb or c# then ask your question there. >>String copsoutput; That needs to be lower-case s on string string copsoutput;
>>to assignt the output to a varaible would I do something like Yes -- you got the idea :) |
| ||
| Re: Search through a file for a string lucky I'm trying to write a c++ program then ;) anyhow when i try to complie the app using while (std::getline(is, line)) I receive the following error: cannot convert std::string to const void for argument 2 to ssize_t write(int, const void*, size_t) |
| ||
| Re: Search through a file for a string >>cannot convert std::string to const void for argument 2 to ssize_t write(int, const void*, size_t) the function write is wanting a pointer as the second parameter and you are passing std::string. The third parameter is also wrong. try this: write(lcd,copsoutput.c_str(), copsoutput.length()); |
| ||
| Re: Search through a file for a string now the app compiles but when I run it I thrown out with terminate called after throwing an instance of 'std::out_of_range' |
| ||
| Re: Search through a file for a string what is secondrow ? while (std::getline(is, line)) |
| All times are GMT -4. The time now is 10:06 am. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC