•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 423,494 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,734 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 276 | Replies: 8
![]() |
| |
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 929
Reputation:
Rep Power: 5
Solved Threads: 66
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.
The hardest part is opening the file, then it's just like reading input from cin:
#include <fstream>
#include <iostream>
#include <string>
int main()
{
std::ifstream is("myfile");
std::string line;
while (std::getline(is, line)) {
std::string::size_type start = line.find("AT+COPS");
if (start != std::string::npos)
std::cout << line.substr(start) << '\n';
}
} If at first you don't succeed, keep on sucking until you do succeed.
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
The hardest part is opening the file, then it's just like reading input from cin:
#include <fstream> #include <iostream> #include <string> int main() { std::ifstream is("myfile"); std::string line; while (std::getline(is, line)) { std::string::size_type start = line.find("AT+COPS"); if (start != std::string::npos) std::cout << line.substr(start) << '\n'; } }
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
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation:
Rep Power: 38
Solved Threads: 929
>> 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
>>to assignt the output to a varaible would I do something like
Yes -- you got the idea
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
Last edited by Ancient Dragon : May 19th, 2008 at 12:08 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
lucky I'm trying to write a c++ program then
anyhow when i try to complie the app using
I receive the following error:
cannot convert std::string to const void for argument 2 to ssize_t write(int, const void*, size_t)
anyhow when i try to complie the app using
while (std::getline(is, line))
{
std::string::size_type start = line.find("+COPS:");
if (start != std::string::npos)
write(lcd,secondrow,sizeof(secondrow));
copsoutput = line.substr(start);
write(lcd,copsoutput,sizeof(copsoutput));
}I receive the following error:
cannot convert std::string to const void for argument 2 to ssize_t write(int, const void*, size_t)
Last edited by uk101man : May 19th, 2008 at 12:28 pm.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation:
Rep Power: 38
Solved Threads: 929
>>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:
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()); Last edited by Ancient Dragon : May 19th, 2008 at 12:37 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: May 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
now the app compiles but when I run it I thrown out with
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr Aborted
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,123
Reputation:
Rep Power: 38
Solved Threads: 929
what is secondrow ?
while (std::getline(is, line))
{
std::string::size_type start = line.find("+COPS:");
if (start != std::string::npos)
{
write(lcd,secondrow,sizeof(secondrow));
copsoutput = line.substr(start);
write(lcd,copsoutput.c_str(), copsoutput.length());
}
} Last edited by Ancient Dragon : May 19th, 2008 at 1:12 pm.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsense adult advertising biometrics blogging book business coding community copyright cult of the dead cow data development earth engine europe forum google hacking image recognition internet search legal malware marketing mcafee microsoft monetization msn news pagerank photo privacy publishing ratings revenue search search engine security seo sex software spyware support technical video video search web webmaster wiki yahoo
- C File handling - search within file without reading content? (C++)
- Replacing text within a file using awk (Shell Scripting)
- Searching a file for a string (C++)
- problem with incrementing numbers in a file (Perl)
- My Way Search Assistant (ive run all the scans already) (Viruses, Spyware and other Nasties)
- String search in a file compare? (Computer Science and Software Design)
Other Threads in the C++ Forum
- Previous Thread: How to restrict memory usage of a c++ program
- Next Thread: Order Tracking sytem. Please help assp. I have no idea how to do!!!!!!!!!!!!!!!!!!



Hybrid Mode