PDA

View Full Version : cstdio QT C++



nhs_0702
15th April 2010, 18:47
#ifndef READWRITEFILE_H
#define READWRITEFILE_H

#include <string>
#include <iostream>
#include <fstream>
#include <assert.h>
#include <vector>
//#include <stdlib.h>

#include "../Misc.h"

using namespace std;

/*!
This class can be written to a file or read from a file.
*/
class InfoReadWrite
{
public:
InfoReadWrite();

//!Read the class from a file
void Read(string filename);

//!Write the class to a file
void Write(string filename);

//!Returns the expected data
vector<float> getData();

//!Saves the members to a file
void setData(vector<float> in);

//!Returns the timestamp of the file read.
string get_timestamp();

private:

//!Loads the whole file in a string
string load_txt(string filename_in);

//!Save a string in a file
void save_txt(string filename_out, string out);

/*!
mess_in = a message
left = the left separator
left = the right separator
...will give the last occurence of the match
*/
string find_subs_between(string mess_in, string left, string right);

//Data that is read/written
float DeviceNo;
float DownloadB;
float UploadB;
string Timestamp;
};

#endif




i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:165: error: '::snprintf' has not been declared
i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:168: error: '::vsnprintf' has not been declared
i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:176: error: '__gnu_cxx::snprintf' has not been declared
i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:179: error: '__gnu_cxx::vsnprintf' has not been declared

why error ?

squidge
15th April 2010, 19:08
Why are you using C i/o function in a C++ project?

snprintf is part of stdio.h

xlink
12th January 2011, 17:51
After speding most of my day trying to figure this out i found that changing "#include <fstream>" to #"include <stdio.h>" fixed it.. in case somebody else has this problem.

Touna
20th April 2012, 15:49
I have the same error like you and when changing the #include the problem is not solved and have this errors that appear:

..\Projet\mythread.cpp:80: error: aggregate 'std::ifstream file' has incomplete type and cannot be defined

..\Projet\mythread.cpp:82: error: incomplete type 'std::ifstream' used in nested name specifier

Please how can i solve this? Thanks

wysota
20th April 2012, 16:27
These are not the same:


i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:165: error: '::snprintf' has not been declared
i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:168: error: '::vsnprintf' has not been declared
i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:176: error: '__gnu_cxx::snprintf' has not been declared
i:\programfiles\qtcreator4_62\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:179: error: '__gnu_cxx::vsnprintf' has not been declared


..\Projet\mythread.cpp:80: error: aggregate 'std::ifstream file' has incomplete type and cannot be defined
..\Projet\mythread.cpp:82: error: incomplete type 'std::ifstream' used in nested name specifier

The solution to your problem is to #include <ifstream>.

Touna
20th April 2012, 16:47
I started with including #include <ifstream>
But I have these errors:


c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:165: error: '::snprintf' has not been declared

c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:168: error: '::vsnprintf' has not been declared

c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:176: error: '__gnu_cxx::snprintf' has not been declared

c:\qt\2010.05\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/cstdio:179: error: '__gnu_cxx::vsnprintf' has not been declared

wysota
20th April 2012, 16:54
Great. Now include stdio.h as well.

Touna
20th April 2012, 17:02
I have included this after reading this post

After speding most of my day trying to figure this out i found that changing "#include <fstream>" to #"include <stdio.h>" fixed it.. in case somebody else has this problem.

but have the followinf errors:

..\Projet\mythread.cpp:80: error: aggregate 'std::ifstream file' has incomplete type and cannot be defined

..\Projet\mythread.cpp:82: error: incomplete type 'std::ifstream' used in nested name specifier

wysota
20th April 2012, 17:35
So you have both stdio.h and ifstream included and you get that error?

Touna
20th April 2012, 17:52
I have resolved this but using QTextStream
Thanks!!!

d_stranz
22nd April 2012, 00:13
I have resolved this but using QTextStream

In other words, you really have no clue what you were doing wrong, despite everyone here telling you exactly what was needed. You'll become a much better programmer if you start trying to understand problems instead of trying things at random until something finally works.

Touna
22nd April 2012, 01:07
You are right understanding errors is important but I'm pressed by time, I have a project that should be delivered in May, that's why i have no more time to spend on this

wysota
23rd April 2012, 11:04
And because of this time pressure you spent 5 days on a problem that could have been solved in 5 seconds. That would leave you with 119 hours, 59 minutes and 55 seconds of time to spend on learning to solve problems such as this one.

Touna
23rd April 2012, 11:14
I'm sorry to tell you that the mathematic operation that you have done is wrong :(
posted on 20th April 15:49 and the problem is resolved at 17:52 for the same day
thus i spended 2 hours 3 min to solve the problem

wysota
23rd April 2012, 11:27
That's still 2 hours and 3 minutes too much. And you didn't solve the problem. You worked around it. The difference between a solution and a workaround is that in the latter situation the issue is likely to arise again.